-->
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.  [ 6 posts ] 
Author Message
 Post subject: MapGenerator iggnores @Id annotation
PostPosted: Fri Mar 24, 2006 9:43 am 
Newbie

Joined: Fri Mar 24, 2006 9:31 am
Posts: 10
Location: Berlin, Germany
I have a class with an id field and with the @Id annotation but net.sf.hibernate.tool.class2hbm.MapGenerator does not generate any mapping for this class claiming that there is no UID defined in the class.
What did I wrong ?

Hibernate version:
2.1.3

Class definition:

@Entity
public class A {
@Id
private int id;
@Id
public final int getId() {
return id;
}
}

generated mapping:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<!-- hibernate.bug.A cannot be added, no UID found! -->
<hibernate-mapping>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 24, 2006 10:22 am 
Newbie

Joined: Tue Jan 03, 2006 7:30 am
Posts: 18
Location: Budapest, Hungary
You should decide if you want to annotate the getters or the fields themselves, and then stick to that decision. Don't annotate both, it will probably confuse Hibernate. Try removing one of the @Id annotations and see if you still get an error.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 25, 2006 9:49 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
so you managed to make the annotations working with Hibernate 2.1.3. Nice ;-)

_________________
Emmanuel


Top
 Profile  
 
 Post subject: MapGenerator ignorres @Id annotation
PostPosted: Wed Mar 29, 2006 5:11 am 
Newbie

Joined: Fri Mar 24, 2006 9:31 am
Posts: 10
Location: Berlin, Germany
tpalfalvi wrote:
You should decide if you want to annotate the getters or the fields themselves, and then stick to that decision. Don't annotate both, it will probably confuse Hibernate. Try removing one of the @Id annotations and see if you still get an error.


I tried it with the following:
Code:
@Entity
public class A implements IA {
    private int id;
    @Id
    public final int getId() {
        return id;
    }
    public B getB() {
        return null;
    }
}

But the result is the same as before:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<!-- hibernate.bug.A cannot be added, no UID found! -->
<hibernate-mapping>
</hibernate-mapping>


Top
 Profile  
 
 Post subject: MapGenerator ignorres @Id annotation
PostPosted: Wed Mar 29, 2006 5:25 am 
Newbie

Joined: Fri Mar 24, 2006 9:31 am
Posts: 10
Location: Berlin, Germany
emmanuel wrote:
so you managed to make the annotations working with Hibernate 2.1.3. Nice ;-)


I think I didn't manage to make the annotations working with Hibernate 2.1.3. It is still not working.
do you have any hint to get it working?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 31, 2006 8:08 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
I think you are mixing incompatible stuff.

e.g. net.sf.hibernate.tool.class2hbm is a deprecated class to hibernate 2 mapping file tool. This tools has no clue about annotations.

If you *really* want to generate hibernate 2 mappings from annotations the way to go is to use Hibernate Tools (tools.hibernate.org) with some custom templates.

The tool will allow you to parse the annotated classes into hibernate meta model from which you can generate mappings via the <hbm2hbmxml/> task. You will need to customize some of the output since it currently generates H3 compliant files, but it should be possible to tweak the templates to be readable by hibernate 2.

_________________
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.  [ 6 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.