-->
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.  [ 13 posts ] 
Author Message
 Post subject: How to generate class path from schema name
PostPosted: Fri Jun 16, 2006 11:50 am 
Regular
Regular

Joined: Wed Sep 28, 2005 6:45 pm
Posts: 56
I have got two tables with the same names in two different schemas. When I try to reverse engineer I get this error message:

org.hibernate.cfg.JDBCBinderException: Duplicate class name 'no.Image' for 'org.hibernate.mapping.Table(etel.image)'. Same name where generated for 'org.hibernate.mapping.Table(etel.image)'

I would like to generate two classes (from the two tables: crm.Image and etel.Image), called no.crm.Image and no.etel.Image instead of one class called no.Image.

(There are two similair tables in the same database because two legacy databases were merged)

I can't do it in a two step process because the two schemaes are getting integrated by foreign keys...


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 17, 2006 3:48 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
use a reveng.xml to rename the destination class for the conflicting class.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 20, 2006 6:59 am 
Regular
Regular

Joined: Wed Sep 28, 2005 6:45 pm
Posts: 56
It seems I need to have unique entitynames as well, because otherwise I get the following error message:

org.hibernate.AnnotationException: Use of the same entity name twice: Timage

This isn't strange at all since I have got two entities like this:

Code:
package crm;
@Entity
@Table(name = "timage", schema = "crm", uniqueConstraints = {})
public class Timage implements java.io.Serializable {
...

package etel;
@Entity
@Table(name = "timage", schema = "etel", uniqueConstraints = {})
public class Timage implements java.io.Serializable {
...


If I edit the java files manually to:
Code:
package crm;
@Entity(name="crm.Timage")
@Table(name = "timage", schema = "crm", uniqueConstraints = {})
public class Timage implements java.io.Serializable {
...

package etel;
@Entity(name="etel.Timage")
@Table(name = "timage", schema = "etel", uniqueConstraints = {})
public class Timage implements java.io.Serializable {
...


it works, but I would like to be able to reverse-enginer without any manual steps.

What I want is to have the Entities name like this @Entity(name="schemaname.tablename") instead of just @Entity which is the same as writeing @Entity(name="tablename")

I already have a reverse-engineering strategyfile that extends DelegatingReverseEngineeringStrategy so that the files use the sequences in postgres, but I can't see any method in DelegatingReverseEngineeringStrategy for changeing the entityname.

Thanks in advance for any help :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 20, 2006 7:03 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you need to return the proper class name from tableToClassName(TableIdentifier tableIdentifier); and it should just work.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 20, 2006 7:14 am 
Regular
Regular

Joined: Wed Sep 28, 2005 6:45 pm
Posts: 56
I don't really want to change the classname Timage to EtelTimage.

I just want to change the entityname if that is possible - or adviceable?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 20, 2006 7:23 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
huh ? Your should return the *full* class entityname then it will work.

You don't need to have EtelTimage, but just (as you already have shown) have two classes TImage in two different packages.)

In this case different entityname occurs automatically and thus you don't need explicit different entitynames.

the tools doesn't support reveng entitynames!=classname, but it does support same simple classname in different packages.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 20, 2006 7:51 am 
Regular
Regular

Joined: Wed Sep 28, 2005 6:45 pm
Posts: 56
I think I have not been good at explaining the problem, or maybe I am misunderstanding your answer :(

The problem occurs when I try to create the session factory with code like this:

Code:
sessionFactory = new AnnotationConfiguration().buildSessionFactory();


the hibernate.cfg.xml looks like this:

Code:
<?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>
        ....
        <mapping class="crm.Timage" />
        ....
        <mapping class="etel.Timage" />
        ...
    </session-factory>
</hibernate-configuration>


My hibernate.reveng.xml file looks like this:
Code:
<?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 match-schema="etel" package="etel" match-name="timage"/>
  ...
  <table-filter match-schema="crm" package="crm" match-name="timage"/>
  ...


As far as I can understand, the AnnotationException occurs because the entity names aren't specified, so the entity names defaults to the classname, not packagename+classname. Therefore, there are two entities with the same name, Timage...

I don't get how overriding tableToClassName will help me, as it is already returning etel.Timage and crm.Timage as far as I can understand...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 20, 2006 7:55 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hmm....annotationconfiguration imo should work outofthebox with this...maybe you need to disable auto-import or something.

i'll need to check with emmanuel.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 20, 2006 8:05 am 
Regular
Regular

Joined: Wed Sep 28, 2005 6:45 pm
Posts: 56
I think the subject might be mentioned here:
http://opensource.atlassian.com/project ... se/ANN-341

but I am not really any closer to a automatic solution :(


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 20, 2006 8:12 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
looks like a correct match.

so to fix this in your setup go in and change the templates to always add an @Entity("fullqualifiedclassname") to the class.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 20, 2006 8:32 am 
Regular
Regular

Joined: Wed Sep 28, 2005 6:45 pm
Posts: 56
That was what I wanted to do, but I don't know how to do it :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 20, 2006 9:13 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
copy pojo/Ejb3TypeDeclaration.ftl from hibernate-tools.jar to a directoy, e.g. "templates/pojo" (do remember to keep the pojo directory name)

change it's name assignment to $pojo.qualifiedDeclarationName and then set template path to point to the "templates" directory.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 20, 2006 9:57 am 
Regular
Regular

Joined: Wed Sep 28, 2005 6:45 pm
Posts: 56
Thanks, that was just what I needed :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 13 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.