-->
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.  [ 4 posts ] 
Author Message
 Post subject: Finding beans using entity manager
PostPosted: Fri Nov 17, 2006 9:48 am 
Newbie

Joined: Fri Nov 17, 2006 9:30 am
Posts: 2
Location: Warsaw, POLAND
I have tables material, attribute and material_attribute (one-to-many - material-attributes) associacion.
Attribute have columns id, name, value.
Material_attribute have columns material_id, attribute_id.
Material have column id.
I can get attributes by material.getAttributes()



Question is:

How to find bean attribute using EntityManager em.find(Attribute.class, if I know material_id and name) ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 17, 2006 11:20 am 
Senior
Senior

Joined: Tue Jul 25, 2006 9:05 am
Posts: 163
Location: Stuttgart/Karlsruhe, Germany
Hi,

I hope i have understood your question correctly, you want to find an Attribute entity using the EntityManager.find(), is that correct ?

Assuming it is, you can only use EntityManager.find() if you know the primary key of the entity (Id in your case). You have stated that you only know the the Material_Id and the Name, you will probably have to use a query such as:

Code:
List result = em.createQuery("FROM Atrribute a WHERE a.name = :name").setParameter("name", "<name you know>")
                                .getResultList();


Cheers,

Andy

_________________
Rules are only there to be broken


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 17, 2006 12:15 pm 
Newbie

Joined: Fri Nov 17, 2006 9:30 am
Posts: 2
Location: Warsaw, POLAND
Ok, you understood me, thank you.
Now I see that entity manager can't find beans based on data from more than one table, but only from one table primary key.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 23, 2006 1:13 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
bhaal wrote:
Ok, you understood me, thank you.
Now I see that entity manager can't find beans based on data from more than one table, but only from one table primary key.


this is obviously wrong. HQL works at the object level, not the database level

_________________
Emmanuel


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