persistence@glassfish.java.net

Re: _at_OneToMany - _at_ManyToOne WebService and _at_XmlRootElement

From: kriskross <kristian_at_smartere.no>
Date: Tue, 18 Sep 2007 23:31:41 -0700 (PDT)

Hi.
I have not bin able to solve this problem.
It's all about @OneToMany - @ManyToOne relations in entitys.
As long as I use my entitys in a session bean, there is no problem.
But, when I try to use them as objects in a webservice I'll get plenty of
errors.
I've tried serveral methods with @XmlRootElement and @XmlTransient with no
luck.

Using the webservice I'm able to create objects, connect objects, but when I
try to recive an object from the db it allways gives errors.

So, if you have anything, any tips or other questions, please let me know.
I've bin strugling with this for over a year now.

Best Regards
Kristian


Marina Vatkina wrote:
>
> Hi,
>
> Did you solve your problem? If not, can you please explain what does it
> mean
> "does not set any Produkt"?
>
> thanks,
> -marina
>
> kriskross wrote:
>> Hi
>> Hope someone can helpe me. I'm stuck here.Having two objects:
>>
>> @XmlRootElement
>> @Entity
>> public class Produkt implements Serializable {
>>
>> @Id
>> @GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
>> "Produkt_id_seq")
>> private Integer id;
>> ...
>> @XmlElement(name = "varelagers")
>> @OneToMany(cascade = CascadeType.ALL, mappedBy = "produkt", fetch =
>> FetchType.EAGER)
>> private List<Varelager> varelagers;
>>
>> public List<Varelager> getVarelager() {
>> return this.varelagers;
>> }
>> ..
>> }
>>
>>
>> and
>> @Entity
>> public class Varelager implements Serializable {
>> @Id
>> @GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
>> "Varelager_id_seq")
>> private Integer id;
>>
>> ......
>>
>> @ManyToOne
>> @JoinColumn(name = "produkt_id")
>> private Produkt produkt;
>>
>> @ManyToOne
>> @JoinColumn(name = "storelse_id")
>> private Storelse storelse;
>>
>> public Produkt getProdukt() {
>> return produkt;
>> }
>>
>> public void setProdukt(Produkt produkt) {
>> this.produkt = produkt;
>> }
>> }
>>
>> I've created an webservice that exposes both produkt and varelager.
>> And I'm trying to add a "varelager" to "produkt", using the webservice.
>> But here my objects does not have all the same methods.
>> I'm missing Varelager.getProdukt(), and Varelager.setProdukt(Produkt
>> produkt).
>>
>> Anyone who can tell me why??
>>
>>
>> I've allso tried this as a workarround
>> Produkt p = webservice.getproddukt(new Integer(1));
>> Varelager vl = new Varelager();
>> vl = webservice.createVarelager(vl);
>> p.getVarelagers().add(vl);
>> webservice.editProdukt(p);
>>
>> This creates the varelager object, but does not set any Produkt.
>> Any other way?
>
>

-- 
View this message in context: http://www.nabble.com/%40OneToMany---%40ManyToOne-WebService-and-%40XmlRootElement-tf4405404.html#a12771562
Sent from the java.net - glassfish persistence mailing list archive at Nabble.com.