-
1. mapping unidirectional relation with parameterised compound
andy.2003 Jan 16, 2006 7:04 AM (in response to andy.2003)tile was cut:
mapping unidirectional relation with parameterised compound foreign keys -
2. Re: mapping unidirectional relation with parameterised compo
cyril.joui Jan 16, 2006 7:52 AM (in response to andy.2003)Hello,
Did you try to map your Collection and after add your getProductDescription(int pLangugeId) (and make a while to search the good description for the specified language ?)
It's not a very clean solution.
I will search for cleaner solution ;)
Good luck
@soon -
3. Re: mapping unidirectional relation with parameterised compo
andy.2003 Jan 16, 2006 9:02 AM (in response to andy.2003)Yes, I managed to set up a OneToMany relation like:
public Set<Description> getDescriptions();
but this is not what I'm searching for. I dont want to fetch all description-entries for an product, I only need the entry for the specified language. -
4. Re: mapping unidirectional relation with parameterised compo
cyril.joui Jan 16, 2006 9:05 AM (in response to andy.2003)I think you must use a Session Bean Façade to initialize your Description (by an EJB QL).
Why do you think about it ?
I think you have already a session bean (to represent a DAO or a service) ?
So it would be easy to set the good description for the current language of user for example. -
5. Re: mapping unidirectional relation with parameterised compo
andy.2003 Jan 16, 2006 9:23 AM (in response to andy.2003)I dont have a session bean at the moment (but should be no problem)
Is there no way to get a method in the Product Class to get the description for the specified language?
I don't understand how you want to "initialize" the Description ...
Do you mean that I should add a NamedQuery like this:@Entity @NamedQuery(name="getProductDescription", queryString="Select d from Description d where d.language_id >= :language_id") public class Description{ ... }
But in this case I dont have the current Product...
If I choose this:@Entity @NamedQuery(name="getProductDescription", queryString="Select d from Description d where d.language_id >= :language_id and d.product_id >= :product_id") public class Description{ ... }
I need both Id's, hmmm, this should be possible.
But there is the next problem: If I set up the Entity like this:... @Id private int product_id; @Id private int language_id; ...
the table is set up wiht only 1 PK (e.g. product_id). I thought I only need a PK-Class for complex PKs (two integer seems not to be complex)
So if I have to set up a PK-Class, can I use the NamedQuery as listed above? (and do I need a PK-Class for two int-values?)
Thank you so far!
Andreas -
6. Re: mapping unidirectional relation with parameterised compo
cyril.joui Jan 16, 2006 10:11 AM (in response to andy.2003)Did you try to make 2 relationships in your description POJO ?
In hibernate there was ternary Associations : http://www.xylax.net/hibernate/ternary.html
I haven't tried this but I think you can define the two relationship and set the primary key with JoinColumn annotation.
I am not sure !
Look at this :
http://www.goobsoft.com/resin-doc/ejb3/cmp-table.xtp#@Entity
At the @JoinColumn.
If you try it can you tell me if it works ?
Thanks. -
7. Re: mapping unidirectional relation with parameterised compo
andy.2003 Jan 16, 2006 10:37 AM (in response to andy.2003)I want a unidirectional access to the Description - Class, this means, in the Description - Class there is no variable storing the Product, so I cant create a ManyToOne mapping.
If I setup following mapping in the Product Class I get only one PK in the Description Table:@OneToMany public Set<Description> getDescriptions(){ return ivDescription; }
... -
8. Re: mapping unidirectional relation with parameterised compo
cyril.joui Jan 16, 2006 10:49 AM (in response to andy.2003)Yes, I see...
You try to use an existing DataBase ...
I saw that :
http://jroller.com/page/raghukodali?entry=ejb_3_annotations_for_mapping
I think it can help you.