同一目录中的hibernate.hbm2ddl.import_files不起作用

时间:2015-10-12 09:48:05

标签: java sql database hibernate import

我正在尝试使用hibernate.hbm2ddl.import_files在webapp启动时运行sql脚本,但这似乎并没有起作用。我在persistence.properties中使用以下内容:

dataSource.driverClassName=com.mysql.jdbc.Driver
dataSource.url=jdbc:mysql://localhost/rays_rentals?createDatabaseIfNotExist=true
dataSource.username=root
dataSource.password=

hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
hibernate.show_sql=true
hibernate.hbm2ddl.auto=create

hibernate.hbm2ddl.import_files=bikes.sql

我的bikes.sql文件保存在与我的属性文件相同的位置。 这是我的sql文件:

INSERT INTO `bikes` (`id`, `brand`, `model`) VALUES (1, 'Giant', 'Propel Advanced 0');

这是我的自行车模型:

package com.BrightFuture.RaysRentalSystem.bikes;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Proxy;

@Entity
@Proxy(lazy = false)
@Table(name = "bikes")
public class Bike {

@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;

@OneToMany(mappedBy="bike", cascade=CascadeType.ALL)
private List<BikeRecord> bikeRecords = new ArrayList<BikeRecord>();

@Column(name="brand", nullable=false)
private String brand;

@Column(name="model", nullable=false)
private String model;
}

感谢。

2 个答案:

答案 0 :(得分:0)

我解决了这个问题。我的问题中的一切都是正确的......我只是在JpaConfig中错过了它的配置

答案 1 :(得分:-2)

请使用以下属性修改您的属性文件: hibernate.hbm2ddl.auto=update

相关问题