This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Cloud Application Architecture Patterns: Designing, Building, and Modernizing for the Cloud and have Kyle Brown, Bobby Woolf and Joseph Yodor on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Hibernate/Spring/Jboss Annotations + Entity Mapping problems

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic