我需要使用带有 EJB3 注释的 java 类创建 Hibernate XML 映射文件。我使用Eclipse Java EE IDE下的 Hibernate Tools for Web Developers Juno Service Release 2 。用于创建一个 Hibernate XML Mapping 文件,如本文所述 但我有同样的问题(在那篇文章中指出):EJB3 注释将被忽略。
如果我有以下 POJO:
package org.hibernate.tutorial.domain;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import org.hibernate.annotations.GenericGenerator;
@Entity
@Table(name = "EVENTS")
public class Event {
@Id
@GenericGenerator(name = "eGen", strategy = "uuid")
@GeneratedValue(generator = "eGen")
@Column(name = "EVENT_ID")
private String id;
@Column(name = "EVENT_TITLE", length = 2730)
private String title;
@Column(name = "EVENT_LONG_TITLE", length = 130)
private String longTitle;
public String getLongTitle() {
return longTitle;
}
public void setLongTitle(String longTitle) {
this.longTitle = longTitle;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "EVENT_DATE")
private Date date;
public Event() {
}
public String getId() {
return id;
}
private void setId(String id) {
this.id = id;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
然后会生成下面的mapper
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 07.05.2013 11:08:58 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="org.hibernate.tutorial.domain.Event" table="EVENT">
<id name="id" type="java.lang.String">
<column name="ID" />
<generator class="assigned" />
</id>
<property name="title" type="java.lang.String">
<column name="TITLE" />
</property>
<property name="longTitle" type="java.lang.String">
<column name="LONGTITLE" />
</property>
<property name="date" type="java.util.Date">
<column name="DATE" />
</property>
</class>
</hibernate-mapping>
非常感谢您的回答!