关于hibernate实体类

  给的数据库模型是sql2005的,然后在powerdesigner把数据库模型改成mysql的去建实体,建不上,貌似好多东西要改。

  要做以下几件事:

  1,加上uuid的东西,生成唯一id,类型是String,Java中实体类主键上加

  @GenericGenerator(name="systemUUID",strategy="uuid")
  @GeneratedValue(generator="systemUUID")

  有些用自增的感觉会比较好些。

  2,要把int类型改成integer,因为int的默认值是0,插入会有默认值。

  3,貌似hibernate直接生成的关系都是一对多的,一对一的忘记怎么弄了,还有多对多的还要建第三方表,明天要研究研究这个。

  4,每个表的递增流水号不知道是干什么的。

  其他:

[11-05 13:43:36] [RMI TCP Connection(3)-127.0.0.1] [ERROR][org.springframework.web.context.ContextLoader-331]-Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [application-context.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Repeated column in mapping for entity: com.shinowit.entity.TMeStockInfo column: MerchandiseID (should be mapped with insert="false" update="false")

百度说是不同的属性映射为相同的字段,重复映射同一个字段,就会出现这个错误;

还没解决。


解决方法:
确实是不同的属性映射了相同的字段,比如之前有一个

private int roleId;

我又加了一个一对多的关系

private Role role;

并且Role里有roleId,这就重复映射了,在通过表建实体的时候不要勾选roleId就可以了。

[RMI TCP Connection(3)-127.0.0.1] [ERROR][org.hibernate.tool.hbm2ddl.SchemaUpdate-237]

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Describe varchar(255), ID integer, MerchandiseAB varchar(255), MerchandiseName v' at line 1

解决方法:

百度到是建到Mysql表的时候Describe 关键字冲突了,把名字改下就好了。

原文地址:https://www.cnblogs.com/chfg/p/4077451.html