This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Hibernate/Spring/Jboss Annotations + Entity Mapping problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate/Spring/Jboss Annotations + Entity Mapping problems" Watch "Hibernate/Spring/Jboss Annotations + Entity Mapping problems" New topic
Author

Hibernate/Spring/Jboss Annotations + Entity Mapping problems

Bal Mark
Greenhorn

Joined: Sep 27, 2002
Posts: 19
Hi All,

Hopefully someone can help with my problem, I'll give some detailed info below, but the summary is

I'm trying to map an Entity class to a property in another Entity, and I'm not having much luck, there's no error when jboss starts up, but when I try a hql query for example, I get an error 'could not resolve property'

in my applicationContext.xml I have



This is fine, seems to pickup the classes

my classes are more or less


and



the fields in the tables are
my_session ->
int id
int device_id
int session_id

device ->
int id
varchar guid


I tried using @Embedded for getDevice in the MySession class, but on queries it complained with something similar to 'cannot find column in field list' and the sql that was generated wasn't doing any join on the devices table, it was looking for device_id in the MySession's table.

When I try to do



it fails on the createQuery with



Thanks for reading this far, and hopefully you can help ;)
I'm trying to avoid any hbm.xml files (migrating away from all that at the moment) and hoping to use pure annotations

hmm what I'm basically trying to do with Annotations what you could do with


Do if I did a hql query "from MySession where device.guid = 'testguid' " ... it would return me the MySession with the Device that has guid = 'testguid'


Kindest regards

Bal
Bal Mark
Greenhorn

Joined: Sep 27, 2002
Posts: 19
Am I way off the mark?

Should I be using @Embedded or just a simple

@Column(name="device_id")
Device device = null;

and my problem lies elsewhere?

Wondering if it's some combination of incompatible jars

Am I wrong in thinking I can do this all through javax.persistence Annotations and settings the annotationclasses in the sessionFactory?

I could really use a few pointers .. so far swapping jars in /jboss/common/lib out and replacing with latest from the 3.6.5-final dist package has made no difference
Bal Mark
Greenhorn

Joined: Sep 27, 2002
Posts: 19
Using



I get the error


I'd have expected it to say, if it couldnt find the property guid, to complain about not finding it in the Device object, not the MySession object

Bal Mark
Greenhorn

Joined: Sep 27, 2002
Posts: 19
Right so ..

Turns out its all down to where Iw as putting my annotations,
I thought it'd be ok to put them around the variables or getters or mix and match

but to get it working,

I moved all the @Column annotations before the getters.. hey presto .. works ;)

the


with



works
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate/Spring/Jboss Annotations + Entity Mapping problems
 
Similar Threads
creating one session factory from two or more applicationContext files having their own POJO list
Hiberante transaction in Spring
Spring/JPA/TopLink 11g extensions
running before I can crawl ( or how to add Spring to an existing Hibernate standalone app)
Controlling Hibernate Session with Spring