0

i need to create the Hibernate XML Mapping file using the java class with EJB3 annotations. I use the Hibernate Tools under Eclipse Java EE IDE for Web Developers Juno Service Release 2. for to create a Hibernate XML Mapping file like described in this post But i have same problem (noted in that post): The EJB3 annotations will be just ignored.

If i have the following 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;
    }

Then the following mapper will be generated

    <?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>

Thanks a lot for answers!

Kamen Jahr
  • 241
  • 2
  • 7
  • 15

1 Answers1

0

The id generators are diferent, the first one uses "uuid" and the hbm says "assigned", the column names and table name are also diferent.

Ziul
  • 883
  • 1
  • 13
  • 24
  • i know that, but the initial quastion was about generating the correct xml mapping related to source: jpa annotated java class. – Kamen Jahr May 08 '13 at 19:54
  • I don't think there is a way to autoconvert anotations to hbm files... you could do it with a regexp but not with hibernate tools. You will have to map the database into hbm files then manually fix the diferences or with a regexp. – Ziul May 08 '13 at 20:39