如何生成使用Hibernate工具注释域对象 [英] How to generate domain objects with annotations using hibernate tools
问题描述
我使用Eclipse的Hibernate工具来创建域类从我的数据库开始,需要添加JPA注解。
有没有办法添加注释?可能与reveng.xml和逆向工程?应如何做?
生成域code:
公共类国家实现java.io.Serializable { 私人长期身份证;
私人字符串描述;
私人字符串标识;
私人字符串futureuse;
私人设置账户=新的HashSet(0); 公共乡村(){
} 公开国家(长ID,描述字符串,字符串标识符){
this.id = ID;
this.description =描述;
this.identifier =标识符;
}
...
所需code:
@Entity
@Table(name =COUNTRY)
公共类国家实现java.io.Serializable { @ID
@Column(NAME =CNTR_ID)
私人长期身份证;
@Column(NAME =CNTR_FUTUREUSE)
私人字符串futureUse;
@Column(NAME =CNTR_IDENTIFIER)
私人字符串标识;
@Column(NAME =CNTR_DESCRIPTION)
私人字符串描述;
私人设置账户=新的HashSet(0); 公共乡村(){
} 公开国家(长ID,描述字符串,字符串标识符){
this.id = ID;
this.description =描述;
this.identifier =标识符;
}
...
我个人不使用休眠的工具,因为我是pretty满意的Spring Roo。然而,谷歌搜索给我带来了这一点。
由于大多有来自mkyong.com一个很好的教程。如果你走在导出选项卡休眠视角,然后点击code一代配置有生成EJB3注释复选框。
<一个href=\"http://www.mkyong.com/hibernate/how-to-generate-$c$c-with-hibernate-tools/\">http://www.mkyong.com/hibernate/how-to-generate-$c$c-with-hibernate-tools/
这是进一步previous答案证实。
I use Eclipse Hibernate Tools to create domain classes starting from my database and need to add JPA annotations.
Is there a way to add annotations? Possibly with reveng.xml and Reverse Engineering? How should this be done?
Generated domain code:
public class Country implements java.io.Serializable {
private long id;
private String description;
private String identifier;
private String futureuse;
private Set accounts = new HashSet(0);
public Country() {
}
public Country(long id, String description, String identifier) {
this.id = id;
this.description = description;
this.identifier = identifier;
}
...
Needed code:
@Entity
@Table(name = "COUNTRY")
public class Country implements java.io.Serializable {
@Id
@Column(name="CNTR_ID")
private Long id;
@Column(name="CNTR_FUTUREUSE")
private String futureUse;
@Column(name="CNTR_IDENTIFIER")
private String identifier;
@Column(name="CNTR_DESCRIPTION")
private String description;
private Set accounts = new HashSet(0);
public Country() {
}
public Country(long id, String description, String identifier) {
this.id = id;
this.description = description;
this.identifier = identifier;
}
...
I personally don't use hibernate tools, because I'm pretty happy with Spring Roo. However, google search brought me to this.
As mostly there is a nice tutorial from mkyong.com. If you go to "Hibernate perspective" and click "Code generation configuration" in the "Export" tab there is a checkbox for "Generate EJB3 annotations".
http://www.mkyong.com/hibernate/how-to-generate-code-with-hibernate-tools/
This was further confirmed in previous answers.
can hibernate tool generate jpa pojo?
这篇关于如何生成使用Hibernate工具注释域对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!