java - Hibernate with JPA won't create table -
i want create table using hibernate + jpa. problem whenever run code won't create tables. have created empty database. utilize hibernate + jpa + hsql + maven.
here persistence.xml:
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<!-- provider of persistence --> <provider>org.hibernate.ejb.hibernatepersistence</provider> <!-- classes, in jpa-annotations read --> <class>com.mysite.warehousebase.base.productdata</class> <properties> <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcdriver"/> <property name="hibernate.connection.url" value="jdbc:hsqldb:warehouse"/> <property name="hibernate.dialect" value="org.hibernate.dialect.hsqldialect"/> <property name="hibernate.connection.username" value="sa" /> <property name="hibernate.connection.password" value="" /> <property name="hibernate.show_sql" value="true"/> <property name="hibernate.format_sql" value="true"/> <property name="hibernate.hbm2ddl.auto" value="update"/> </properties>
here productdata.java code:
import javax.persistence.cascadetype; import javax.persistence.column; import javax.persistence.entity; import javax.persistence.joincolumn; import javax.persistence.manytoone; import javax.persistence.table; import org.hibernate.annotations.foreignkey; import org.hibernate.validator.notnull; @entity @table(name = "products") public class productdata extends entityclass { private static final long serialversionuid = 1l; /* //product add-on time @notnull @column(name = "added", nullable = false) private date productadded;*/ //product name @notnull @column(name = "productname", nullable = false) private string productname; //product description @column(name = "productdescription", nullable = true) private string productdescription; //product size @column(name = "productsize", nullable = true) private string productsize; //product amount @notnull @column(name = "productamount", nullable = false) private int productamount; //product left //attribute calculated in own method @notnull @column(name = "productleft", nullable = false) private int productleft; //product purchase cost @notnull @column(name = "productprice", nullable = false) private double productprice; //total cost //attribute calculated in own method @notnull @column(name = "totalproductprice", nullable = false) private double totalproductprice; //product sell cost @notnull @column(name = "productsellprice", nullable = false) private double productsellprice; //product sale //attribute calculated in own method @notnull @column(name = "totalsellprice", nullable = false) private double totalsellprice; //difference between cost , sale (total) //attribute calculated in own method @notnull @column(name = "buyselldifference", nullable = false) private double buyselldifference; //product status; ordered, @ warehouse, reserved. //attribute calculated in own method @notnull @column(name = "productstatus", nullable = false) private string productstatus; @column(name = "reservedproducts", nullable = true) private int reservedproducts; /** * setters , getters * */ /** * @return productname */ public string getproductname() { homecoming productname; } /** * @param productname productname set */ public void setproductname(string productname) { this.productname = productname; } /** * @return productdescription */ public string getproductdescription() { homecoming productdescription; } /** * @param productdescription productdescription set */ public void setproductdescription(string productdescription) { this.productdescription = productdescription; } /** * @return productsize */ public string getproductsize() { homecoming productsize; } /** * @param productsize productsize set */ public void setproductsize(string productsize) { this.productsize = productsize; } /** * @return productamount */ public int getproductamount() { homecoming productamount; } /** * @param productamount productamount set */ public void setproductamount(int productamount) { this.productamount = productamount; } /** * @return productleft */ public int getproductleft() { homecoming productleft; } /** * @param productleft productleft set */ public void setproductleft(int productleft) { this.productleft = productleft; } /** * @return productprice */ public double getproductprice() { homecoming productprice; } /** * @param productprice productprice set */ public void setproductprice(double productprice) { this.productprice = productprice; } /** * @return totalproductprice */ public double gettotalproductprice() { homecoming totalproductprice; } /** * @param totalproductprice totalproductprice set */ public void settotalproductprice(double totalproductprice) { this.totalproductprice = totalproductprice; } /** * @return productsellprice */ public double getproductsellprice() { homecoming productsellprice; } /** * @param productsellprice productsellprice set */ public void setproductsellprice(double productsellprice) { this.productsellprice = productsellprice; } /** * @return totalsellprice */ public double gettotalsellprice() { homecoming totalsellprice; } /** * @param totalsellprice totalsellprice set */ public void settotalsellprice(double totalsellprice) { this.totalsellprice = totalsellprice; } /** * @return buyselldifference */ public double getbuyselldifference() { homecoming buyselldifference; } /** * @param buyselldifference buyselldifference set */ public void setbuyselldifference(double buyselldifference) { this.buyselldifference = buyselldifference; } /** * @return productstatus */ public string getproductstatus() { homecoming productstatus; } /** * @param productstatus productstatus set */ public void setproductstatus(string productstatus) { this.productstatus = productstatus; } /** * @return reservedproducts */ public int getreservedproducts() { homecoming reservedproducts; } /** * @param reservedproducts reservedproducts set */ public void setreservedproducts(int reservedproducts) { this.reservedproducts = reservedproducts; } /** * @return productsection */ public productsection getproductsection() { homecoming productsection; } /** * @param productsection productsection set */ public void setproductsection(productsection productsection) { this.productsection = productsection; } public productdata(){ } public productdata(string productname){ this.productname = productname; }
}
and main.java code:
public static void main(string[] args) { datastructuretest testproduct = new datastructuretest(); testproduct.testproductdata(); }
what wrong? why hibernate won't create table needed? have tried using hibernate.hbm2ddl.auto value of "update". won't help.
can seek
<property name="hibernate.hbm2ddl.auto" value="create"/>
also 'transaction-type="resource_local"
defined in persistence xml
java hibernate table jpa
No comments:
Post a Comment