Hibernate 注解 可以自动生成表结构吗?

时间:2022-07-01 13:19:55
以前使用 hibernate 可以生成表结构,代码为:
                  Configuration cfg = new Configuration().configure();
SchemaExport export = new SchemaExport(cfg);
export.create(true, true);
; 今天用了 hibernate 注解,xml 文件都放弃了,发现不能生成了!报:
19:51:37,734  INFO Environment:560 - Hibernate 3.3.2.GA
19:51:37,734  INFO Environment:593 - hibernate.properties not found
19:51:37,750  INFO Environment:771 - Bytecode provider name : javassist
19:51:37,750  INFO Environment:652 - using JDK 1.4 java.sql.Timestamp handling
19:51:37,828  INFO Configuration:1474 - configuring from resource: /hibernate.cfg.xml
19:51:37,828  INFO Configuration:1451 - Configuration resource: /hibernate.cfg.xml
19:51:37,875 DEBUG DTDEntityResolver:64 - trying to resolve system-id [http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd]
19:51:37,875 DEBUG DTDEntityResolver:66 - recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/
19:51:37,890 DEBUG DTDEntityResolver:76 - located [http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd] in classpath
19:51:37,906 DEBUG Configuration:1435 - myeclipse.connection.profile=li
19:51:37,906 DEBUG Configuration:1435 - connection.url=jdbc:oracle:thin:@localhost:1521:demo
19:51:37,906 DEBUG Configuration:1435 - connection.username=ming
19:51:37,906 DEBUG Configuration:1435 - connection.password=ming
19:51:37,906 DEBUG Configuration:1435 - connection.driver_class=oracle.jdbc.driver.OracleDriver
19:51:37,906 DEBUG Configuration:1435 - dialect=org.hibernate.dialect.Oracle9Dialect
19:51:37,921 DEBUG Configuration:1435 - show_sql=true

。。。。。
我也不知道,为什么,,,请问哪位大侠可以帮我解释一下吗!谢谢了~~~

8 个解决方案

#1


关注

#2


还没这么做过
不了解
顶下

#3




19:51:37,906 DEBUG Configuration:1435 - dialect=org.hibernate.dialect.Oracle9Dialect
19:51:37,921 DEBUG Configuration:1435 - show_sql=true 

从控制台看好像是少配了下面这条:
    <property name="hibernate.hbm2ddl.auto" value="update"/>
要自动建表要给hiberbate添加上面这个属性

#4


 暂时还没接触到annotation·

#5


用Configuration cfg = new AnnotationConfiguration().configure(); 

#6


朋友们,使用了 3楼 和 5楼的 做法 ,我发现还是不行!
你们看看: Configuration cfg = new AnnotationConfiguration().configure();
SchemaExport export = new SchemaExport(cfg);
export.create(true, true);

报:deprecated; use either Oracle9iDialect or Oracle10gDialect instead
13:53:25,062 DEBUG AnnotationConfiguration:258 - Execute first pass mapping processing
13:53:25,109 DEBUG AnnotationConfiguration:529 - Process hbm files
13:53:25,109 DEBUG AnnotationConfiguration:537 - Process annotated classes
13:53:25,109  INFO AnnotationBinder:419 - Binding entity from annotated class: com.hnsy.liming.entity.Users
13:53:25,140 DEBUG Ejb3Column:161 - Binding column DTYPE. Unique false. Nullable false.
13:53:25,156 DEBUG EntityBinder:295 - Import with entity name Users
13:53:25,156  INFO EntityBinder:422 - Bind entity com.hnsy.liming.entity.Users on table Users
13:53:25,171 DEBUG AnnotationBinder:1022 - Processing com.hnsy.liming.entity.Users property annotation
13:53:25,187 DEBUG AnnotationBinder:1133 - Processing annotations of com.hnsy.liming.entity.Users.idno
13:53:25,187 DEBUG Ejb3Column:161 - Binding column idno. Unique false. Nullable true.
13:53:25,187 DEBUG AnnotationBinder:1257 - idno is an id
13:53:25,187 DEBUG SimpleValueBinder:220 - building SimpleValue for idno
13:53:25,203 DEBUG PropertyBinder:131 - Building property idno
13:53:25,203 DEBUG AnnotationBinder:1293 - Bind @Id on idno
13:53:25,203 DEBUG AnnotationBinder:1133 - Processing annotations of com.hnsy.liming.entity.Users.uname
13:53:25,203 DEBUG Ejb3Column:161 - Binding column uname. Unique false. Nullable true.
13:53:25,203 DEBUG PropertyBinder:110 - binding property uname with lazy=false
13:53:25,203 DEBUG SimpleValueBinder:220 - building SimpleValue for uname
13:53:25,203 DEBUG PropertyBinder:131 - Building property uname
13:53:25,203 DEBUG AnnotationBinder:1133 - Processing annotations of com.hnsy.liming.entity.Users.usex
13:53:25,203 DEBUG Ejb3Column:161 - Binding column usex. Unique false. Nullable true.
13:53:25,218 DEBUG PropertyBinder:110 - binding property usex with lazy=false
13:53:25,218 DEBUG SimpleValueBinder:220 - building SimpleValue for usex
13:53:25,218 DEBUG PropertyBinder:131 - Building property usex
13:53:25,218 DEBUG AnnotationConfiguration:401 - processing fk mappings (*ToOne and JoinedSubclass)
13:53:25,218 DEBUG Configuration:1167 - processing extends queue
13:53:25,218 DEBUG Configuration:1171 - processing collection mappings
13:53:25,218 DEBUG Configuration:1182 - processing native query and ResultSetMapping mappings
13:53:25,218 DEBUG Configuration:1190 - processing association property references
13:53:25,218 DEBUG Configuration:1212 - processing foreign key constraints

#7


朋友,看了你帖子,我发现时包起冲突了,你仔细看看!而  <property name="hibernate.hbm2ddl.auto" value="update"/> 
这句代码,你可写,可不写的,你可以试试,希望能对你有所帮助,呵呵!

#8


的确是的, 7楼的朋友,你说的太对了,问题解决了哦,,结贴了,呵呵!

#1


关注

#2


还没这么做过
不了解
顶下

#3




19:51:37,906 DEBUG Configuration:1435 - dialect=org.hibernate.dialect.Oracle9Dialect
19:51:37,921 DEBUG Configuration:1435 - show_sql=true 

从控制台看好像是少配了下面这条:
    <property name="hibernate.hbm2ddl.auto" value="update"/>
要自动建表要给hiberbate添加上面这个属性

#4


 暂时还没接触到annotation·

#5


用Configuration cfg = new AnnotationConfiguration().configure(); 

#6


朋友们,使用了 3楼 和 5楼的 做法 ,我发现还是不行!
你们看看: Configuration cfg = new AnnotationConfiguration().configure();
SchemaExport export = new SchemaExport(cfg);
export.create(true, true);

报:deprecated; use either Oracle9iDialect or Oracle10gDialect instead
13:53:25,062 DEBUG AnnotationConfiguration:258 - Execute first pass mapping processing
13:53:25,109 DEBUG AnnotationConfiguration:529 - Process hbm files
13:53:25,109 DEBUG AnnotationConfiguration:537 - Process annotated classes
13:53:25,109  INFO AnnotationBinder:419 - Binding entity from annotated class: com.hnsy.liming.entity.Users
13:53:25,140 DEBUG Ejb3Column:161 - Binding column DTYPE. Unique false. Nullable false.
13:53:25,156 DEBUG EntityBinder:295 - Import with entity name Users
13:53:25,156  INFO EntityBinder:422 - Bind entity com.hnsy.liming.entity.Users on table Users
13:53:25,171 DEBUG AnnotationBinder:1022 - Processing com.hnsy.liming.entity.Users property annotation
13:53:25,187 DEBUG AnnotationBinder:1133 - Processing annotations of com.hnsy.liming.entity.Users.idno
13:53:25,187 DEBUG Ejb3Column:161 - Binding column idno. Unique false. Nullable true.
13:53:25,187 DEBUG AnnotationBinder:1257 - idno is an id
13:53:25,187 DEBUG SimpleValueBinder:220 - building SimpleValue for idno
13:53:25,203 DEBUG PropertyBinder:131 - Building property idno
13:53:25,203 DEBUG AnnotationBinder:1293 - Bind @Id on idno
13:53:25,203 DEBUG AnnotationBinder:1133 - Processing annotations of com.hnsy.liming.entity.Users.uname
13:53:25,203 DEBUG Ejb3Column:161 - Binding column uname. Unique false. Nullable true.
13:53:25,203 DEBUG PropertyBinder:110 - binding property uname with lazy=false
13:53:25,203 DEBUG SimpleValueBinder:220 - building SimpleValue for uname
13:53:25,203 DEBUG PropertyBinder:131 - Building property uname
13:53:25,203 DEBUG AnnotationBinder:1133 - Processing annotations of com.hnsy.liming.entity.Users.usex
13:53:25,203 DEBUG Ejb3Column:161 - Binding column usex. Unique false. Nullable true.
13:53:25,218 DEBUG PropertyBinder:110 - binding property usex with lazy=false
13:53:25,218 DEBUG SimpleValueBinder:220 - building SimpleValue for usex
13:53:25,218 DEBUG PropertyBinder:131 - Building property usex
13:53:25,218 DEBUG AnnotationConfiguration:401 - processing fk mappings (*ToOne and JoinedSubclass)
13:53:25,218 DEBUG Configuration:1167 - processing extends queue
13:53:25,218 DEBUG Configuration:1171 - processing collection mappings
13:53:25,218 DEBUG Configuration:1182 - processing native query and ResultSetMapping mappings
13:53:25,218 DEBUG Configuration:1190 - processing association property references
13:53:25,218 DEBUG Configuration:1212 - processing foreign key constraints

#7


朋友,看了你帖子,我发现时包起冲突了,你仔细看看!而  <property name="hibernate.hbm2ddl.auto" value="update"/> 
这句代码,你可写,可不写的,你可以试试,希望能对你有所帮助,呵呵!

#8


的确是的, 7楼的朋友,你说的太对了,问题解决了哦,,结贴了,呵呵!