openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marc Logemann ...@logemann.org>
Subject Re: Lazy load for detached entities
Date Tue, 11 Sep 2007 09:37:40 GMT
This is of course the manual way but fetch-groups are smarter in my  
oppinion.... But i am using Kodo and it might be that fetch groups  
are not supported in openJPA but i think it is....

--
regards
Marc Logemann
[blog] http://www.logemann.org
[busn] http://www.logentis.de


Am 11.09.2007 um 11:17 schrieb Gene Wu:

> to support lazy load base on your code. Just change the order. Load  
> the object before you close em(this is the context needed for lazy  
> load).
>
> EntityManagerFactory emf = Persistence.createEntityManagerFactory 
> ("pu1");
> EntityManager em = emf.createEntityManager();
> OrdersEntity order = em.find(OrdersEntity.class, .....);
> System.out.println(order.getUser());
> em.close();
> emf.close();
>
> Thanks,
>
> Gene.
>> Date: Tue, 11 Sep 2007 10:30:45 +0300
>> To: users@openjpa.apache.org
>> Subject: Lazy load for detached entities
>> From: eshepelyuk@gmail.com
>>
>> 	Hello !
>>
>> Is there any way to access fields marked with lazy fetching for  
>> detached
>> entities.
>> Im having some code like
>>
>> @Entity
>> @Table(schema = "public", name = "users")
>> public class UsersEntity {
>> 	private Integer userid;
>> 	private List<OrdersEntity> orders;
>>
>> 	@OneToMany(cascade = CascadeType.PERSIST, mappedBy = "user", fetch =
>> FetchType.LAZY)
>> 	public List<OrdersEntity> getOrders() {
>> 		return orders;
>> 	}
>>
>> 	public void setOrders(List<OrdersEntity> orders) {
>> 		this.orders = orders;
>> 	}
>>
>> 	@Id
>> 	@Column(name = "userid", nullable = false)
>> 	@GeneratedValue(strategy = GenerationType.IDENTITY)
>> 	public Integer getUserid() {
>> 		return userid;
>> 	}
>>
>> 	public void setUserid(Integer userid) {
>> 		this.userid = userid;
>> 	}
>> }
>>
>>
>> @Entity
>> @Table(schema = "public", name = "orders")
>> public class OrdersEntity {
>> 	private Integer orderid;
>> 	private UsersEntity user;
>>
>> 	@ManyToOne(fetch = FetchType.LAZY)
>> 	@JoinColumn(name = "userid", nullable = false)
>> 	public UsersEntity getUser() {
>> 		return user;
>> 	}
>>
>> 	public void setUser(UsersEntity user) {
>> 		this.user = user;
>> 	}
>>
>> 	@Id
>> 	@Column(name = "orderid", nullable = false, length = 10)
>> 	@GeneratedValue(strategy = GenerationType.IDENTITY)
>> 	public Integer getOrderid() {
>> 		return orderid;
>> 	}
>>
>> 	public void setOrderid(Integer orderid) {
>> 		this.orderid = orderid;
>> 	}
>> }
>>
>> And my program code
>>
>> EntityManagerFactory emf = Persistence.createEntityManagerFactory 
>> ("pu1");
>> EntityManager em = emf.createEntityManager();
>> OrdersEntity order = em.find(OrdersEntity.class, .....);
>> em.close();
>> System.out.println(order.getUser());
>> emf.close();
>>
>> And it shows null.
>> -- 
>> Best Regards
>> Evgeny K. Shepelyuk
>
> _________________________________________________________________
> Gear up for Halo® 3 with free downloads and an exclusive offer.  
> It’s our way of saying thanks for using Windows Live™.
> http://gethalo3gear.com?ocid=SeptemberWLHalo3_WLHMTxt_2


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message