-->
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.  [ 1 post ] 
Author Message
 Post subject: Transient fields with callback methods
PostPosted: Wed Sep 23, 2009 2:35 pm 
Newbie

Joined: Wed Sep 23, 2009 2:03 pm
Posts: 1
I have an entity which contains several basic fields A, B and C and one complex field X which is not (should not be) mapped to a database column. The idea is to create X from A, B and C when loading an instance, and to deconstruct X into A, B and C when persisting.

The first logical thing to try was something like:

@Entity
class Xxx
{

private String a;

@Transient
private X x;

@PrePersist
public void prePersist()
{
XParts xp = x.deconstruct();
a = xp.getA();
//...
}
//...
}

The problem is, when calling entityManager.merge(xxx); x is lost. Something to do with how the @Transients are handled in JPA. @Transient and @PrePersist don't mix. Ok. Can't argue with the specification I guess.

But, what are the alternatives? I really don't need X in database.

The best I could come up with is:

@Column(insertable=false,updatable=false)
private X x;

Which creates column X, which is always null. If it's really the only way, I can live with that, but it seems hackish at best.

I can't be the only one who run into this problem. Is there any better way to do this?

Or maybe - that would be preferable - there is a way to make @Transient and @PrePersist work together?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.