问题描述
我正在开发一个项目,通过添加Hibernate注释来坚持一些POJO。我遇到的一个问题是,像这样的代码会失败,因为Hibernate试图将
尝试设置属性 hibernate.ejb.naming_strategy 至 org.hibernate.cfg.DefaultComponentSafeNamingStrategyI am developing a project in which I am persisting some POJOs by adding Hibernate annotations. One problem I am running into is that code like this fails, as Hibernate tries to map the sub-fields within the Time_T onto the same column (i.e. startTime.sec and stopTime.sec both try to map to the colum sec, causing an error).
@Entity public class ExampleClass { @Id long eventId; Time_T startTime; Time_T stopTime; } @Embeddable public class Time_T { int sec; int nsec; }
As there will be many occurrences like this throughout the system, it would be nice if there was an option to automatically append a prefix to the column name (e.g. make the columns be startTime_sec, startTime_nsec, stopTime_sec, stopTime_nsec), without having to apply overrides on a per-field basis. Does Hibernate have this capability, or is there any other reasonable work-around?
Try setting the property hibernate.ejb.naming_strategy to org.hibernate.cfg.DefaultComponentSafeNamingStrategy
这篇关于自动为@Embeddable类的列名添加前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!