-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 
Author Message
 Post subject: HibernateTools not generating relationships..
PostPosted: Fri Jul 04, 2008 2:19 pm 
Beginner
Beginner

Joined: Thu Apr 17, 2008 2:03 pm
Posts: 26
I am using Hibernate Tools to generate POJOs and Mapping files. Everything works well but entity relationships are not established properly either in POJOs or Mapping files.

Here is the hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="session1">
<property name="hibernate.dialect">org.hibernate.dialect.DerbyDialect</property>
<property name="hibernate.connection.driver_class">org.apache.derby.jdbc.ClientDriver</property>
<property name="hibernate.connection.url">jdbc:derby://localhost:1527/travel</property>
<property name="hibernate.connection.username">travel</property>
<property name="hibernate.connection.password">travel</property>
</session-factory>
</hibernate-configuration>


hibernate.reveng.xml:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd">
<hibernate-reverse-engineering>
<table-filter exclude="false" match-catalog=".*" match-name="FLIGHT" match-schema=".*"/>
<table-filter exclude="false" match-catalog=".*" match-name="PERSON" match-schema=".*"/>
<table-filter exclude="false" match-catalog=".*" match-name="TRIP" match-schema=".*"/>
<table-filter exclude="false" match-catalog=".*" match-name="TRIPTYPE" match-schema=".*"/>
</hibernate-reverse-engineering>

Person.hbm.xml

<?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 Jul 3, 2008 2:34:25 PM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="travel.Person" table="PERSON" schema="TRAVEL">
<id name="personid" type="int">
<column name="PERSONID" />
<generator class="assigned" />
</id>
<property name="name" type="string">
<column name="NAME" length="50" />
</property>
<property name="jobtitle" type="string">
<column name="JOBTITLE" length="50" />
</property>
<property name="frequentflyer" type="java.lang.Short">
<column name="FREQUENTFLYER" />
</property>
<property name="lastupdated" type="timestamp">
<column name="LASTUPDATED" length="26" />
</property>
<set cascade="all-delete-orphan" inverse="true" lazy="true" name="trips" table="TRIP">
<key column="PERSONID"/>
<one-to-many class="travel.Trip"/>
</set>
</class>
</hibernate-mapping>


I manually added <set>. But I expected the <set> to be generated by default using the hibernate Tools.


Person.java


package travel;
// Generated Jul 3, 2008 2:34:20 PM by Hibernate Tools 3.2.1.GA


import java.util.Date;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
* Person generated by hbm2java
*/
@Entity
@Table(name="PERSON"
,schema="TRAVEL"
)
public class Person implements java.io.Serializable {


private int personid;
private String name;
private String jobtitle;
private Short frequentflyer;
private Date lastupdated;
private Set<Trip> trips;

@OneToMany(mappedBy="personid")
public Set<Trip> getTrips() {
return trips;
}

public void setTrips(Set<Trip> trips) {
this.trips = trips;
}

public Person() {
}


public Person(int personid) {
this.personid = personid;
}
public Person(int personid, String name, String jobtitle, Short frequentflyer, Date lastupdated) {
this.personid = personid;
this.name = name;
this.jobtitle = jobtitle;
this.frequentflyer = frequentflyer;
this.lastupdated = lastupdated;
}

@Id

@Column(name="PERSONID", unique=true, nullable=false)
public int getPersonid() {
return this.personid;
}

public void setPersonid(int personid) {
this.personid = personid;
}

@Column(name="NAME", length=50)
public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}

@Column(name="JOBTITLE", length=50)
public String getJobtitle() {
return this.jobtitle;
}

public void setJobtitle(String jobtitle) {
this.jobtitle = jobtitle;
}

@Column(name="FREQUENTFLYER")
public Short getFrequentflyer() {
return this.frequentflyer;
}

public void setFrequentflyer(Short frequentflyer) {
this.frequentflyer = frequentflyer;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name="LASTUPDATED", length=26)
public Date getLastupdated() {
return this.lastupdated;
}

public void setLastupdated(Date lastupdated) {
this.lastupdated = lastupdated;
}

}

In the same way I had to manually add the code (in bold) in Person.java

Here is how I am generating the POJOs and Mappings:

// Configuring the reverse engineering strategy
try {

cfg = new JDBCMetaDataConfiguration();
OverrideRepository or = new OverrideRepository();
Configuration c = cfg.configure(confFile);
or.addFile(FileUtil.toFile(revengFile));
DefaultReverseEngineeringStrategy strategy = new DefaultReverseEngineeringStrategy();
settings = new ReverseEngineeringSettings(strategy);
settings.setDefaultPackageName(helper.getPackageName());
strategy.setSettings(settings);
cfg.setReverseEngineeringStrategy(or.getReverseEngineeringStrategy(strategy));
cfg.readFromJDBC();
} catch (Exception e) {
Exceptions.printStackTrace(e);
}

// Generating POJOs
try {
if (helper.getDomainGen()) {
POJOExporter exporter = new POJOExporter(cfg, outputDir);
exporter.getProperties().setProperty("jdk", new Boolean(helper.getJavaSyntax()).toString());
exporter.getProperties().setProperty("ejb3", new Boolean(helper.getEjbAnnotation()).toString());
exporter.start();
}
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
}

// Generating Mappings
try {
if (helper.getHbmGen()) {
HibernateMappingExporter exporter = new HibernateMappingExporter(cfg, outputDir);
exporter.start();
}
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
}



Wondering if I have to set anything in order to generate the relationships.
Note that the database has relationships defined.

I appreciate your help

Thanks - G


Top
 Profile  
 
 Post subject: what is the tool?
PostPosted: Sat Jul 05, 2008 11:03 pm 
Newbie

Joined: Wed Jul 02, 2008 10:39 pm
Posts: 6
Location: Hyderabad
Hi Gowri,
What is the tool that you are using.
If you use the myEclipse you can every thing generated including the relation ships.

_________________
Regards,
Racha Satish Kumar,
Visit Me Here!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 07, 2008 3:45 pm 
Beginner
Beginner

Joined: Thu Apr 17, 2008 2:03 pm
Posts: 26
I am using Netbeans as the IDE and I am trying to develop this feature.
I have never used MyEclipse. I tried the same with Eclipse and no relationships were generated too using reveng code generation feature provided by Eclipse.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 09, 2008 12:01 pm 
Beginner
Beginner

Joined: Thu Apr 17, 2008 2:03 pm
Posts: 26
Can anyone answer my question please ? Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 12, 2008 7:48 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
looks like Derby is not reporting the foreignkeys correctly.

Have you tried with latest drivers ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 14, 2008 5:35 pm 
Beginner
Beginner

Joined: Thu Apr 17, 2008 2:03 pm
Posts: 26
Thanks for the reply Max.
I am using the ones from glassfish v2 (glassfish-installer-v2-b52). Do you think I need to get the latest glassfish to see if that works ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 14, 2008 5:51 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
I don't know which ones come bundled with glassfish. I would try with the latest from Derby it self.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 15, 2008 6:43 pm 
Beginner
Beginner

Joined: Thu Apr 17, 2008 2:03 pm
Posts: 26
Max,
As you suggested, I tried with db-derby-10.4.1.3 even then there is no luck.
No relationships were generated. Do you think I need to set anything from code to generate the relationships between the entities ?

Thanks, Gowri


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 05, 2008 12:32 pm 
Newbie

Joined: Wed Jan 19, 2005 2:39 pm
Posts: 16
I have exactly this problem. I'm using the latest derby jdbc drivers and latest hibernate tools. Lots of searching seems to indicate that lots of people are using derby/hibernate successfully, but I can't get past this problem.

Have you had further insight on this issue?

Thanks
M


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 17, 2008 1:53 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Not besides hearing that when users upgrade they get it working....maybe they changed something again and it stopped working ;(

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.