wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Mapping entities Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Mapping entities" Watch "Mapping entities" New topic
Author

Mapping entities

Hernán Quevedo
Ranch Hand

Joined: Mar 18, 2009
Posts: 31
Hey, guys.

Quick question: how do I map entities (POJOs with annotations like @Entity, @Table..., etc.) so hibernate doesn't tell me that someClass is not mapped?

I have this bean:


And when trying to do this:



It throws the exception


I know there is a NamedQuery but hibernate doesn't find it so I'm testing this way first.

Thanks.
Aurelian Tutuianu
Ranch Hand

Joined: May 13, 2004
Posts: 86
On server logs says anything? On deploy to the ejb container?


http://javasign.blogspot.com/
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

When you create/initialize your AnnotationConfiguration object, make sure the Java class is added prior to invoking config. Here I add a class named User:



Validating your Hibernate Development Environment Tutorial

-Cameron McKenzie
Hernán Quevedo
Ranch Hand

Joined: Mar 18, 2009
Posts: 31
Thanks! It worked.
Nevertheless... now it tells me:



Line 54 in stateful session-bean says:


On the other hand, no tables are being generated in mysql/trackman scheme, even though I wrote, on the persistence.xml:


and the console tells me this:



I must be missing something...
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

java.lang.NoClassDefFoundError: ebs/trackman/entities/User


So, you get that when you run your code? That's easy to explain - your compiled User code is not on the runtime classpath. Make sure your JVM can see the compiled class at runtime.

-Cameron McKenzie
Hernán Quevedo
Ranch Hand

Joined: Mar 18, 2009
Posts: 31
Hey, thank you.

Anyway, I have done everything but the JVM doesn't seem to see it, no matter what.

How would you do it? It's amazing how complicated this had turned out to be,
Hernán Quevedo
Ranch Hand

Joined: Mar 18, 2009
Posts: 31
Nope, scratch that...

I did it, it was a problem of locating configuration files correctly.

Now... I swear I saw the JBoss console telling me named queries were getting bounded. All of the sudden, it creates the tables and doesn't bind any named queries, I have to put them manually on the hbm.xml file but it is so much better to have them on their respectively entity-class java file, don't you think?

How do I do that again? I remember that when I managed to bind those named queries at the same time it created the tables, I had this exception telling me it couldn't resolve type java.util.Collection in a @ManyToOne annotation.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mapping entities