[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.rt.eclipselink] Re: JPA and JSP

Enrico ha scritto:
Dear all,

I would like to use jpa on my JSP in order to manage persistance. My problem is with Entity relationship.
JavaBean on JSP allow to set/get primitive java types. So for example I can set by <input> tag on JSP a javabean property.
But if I have two Entity A and B with a relation between them (the following source is just for example...it can have sintax error..but it is just to give you an example):


@Entity
public class A {
   @Id
   private int ida;

   @OnetoOne
   private B b;

}


@Entity public class B { @Id private int idb;

   @OnetoOne
   private A a;
}

and I use this bean in the JSP:

<jsp:useBean id="a"class="A" scope="page" />
<jsp:setProperty name="a" property="*"/>

how can I set the property b of class A?
If it was a primitive type (like an int) I could:

<input type="hidden" name="b"  value="<%....%>">

but it is not a primitive type..it is an object of class B (an entity).

There is any way to use javabean entity with relationship propertis (also OneToMany...with list for example) on JSP beans?

Best Regards,
Enrico


Just a point.
Actually, to solve the problem...I have for an entity with relation 2 properties for any relation. I mean, in the previous example:


@Entity
 public class A {
    @Id
    private int ida;

    @OnetoOne
    private B b;

    @Transient
    private int bId;

 }


@Entity public class B { @Id private int idb;

    @OnetoOne
    private A a;

    @Transient
    private int aId;
 }

so..on the JSP i set/get the transient (no persistent property).
In the set/get of the transient property I then set/get the related persistent field, for example


public void setBId(int bid) {
    this.bId = bid;
	
    //now set the related persistent field
    this.b = findbyid(bid);  //this return a B object with the b id;

 }


this procedure is for me boring, because I need 2 property (and 2 structures If I have onetomany or manyto many relationships: a persistent List and an array[]).


If you have any ideas or you know some better solution please let me know.

Best regards,
Enrico