Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem with JPA @Embeddable class field in @Embedded

909774Feb 9 2012 — edited Feb 15 2012
I have a Embeddable class and Embadded in all of my JPA Entities, the version(in DBUniqueId) field is mandatory for some JPA Entities and for others it should not be present.

My DBUser.java JPA Entity shouldn't have version field(DBUser table doesn't have one) and so I didn't include it in @AttributeOverrides of DBUser.java. when I try to run the JPA query it results in exception

Query:
List<DBUser> userList = (List<DBUser>)entityManager.createQuery(SELECT u FROM DBUser u WHERE u.userId.root=?1 AND u.userId.extension=?2).setParameter(1,"root1").setParameter(2,"ext1").getResultList ();

And The Exception is:
---- Begin backtrace for Nested Throwables
java.sql.SQLException: ORA-00904: "T0"."VERSION": invalid identifier

at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:74)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:131)

How do I inform to JPA Entity to ignore only the version field of the Embeddable in my JPA Entity @Embedded place.
So the above query can successful. Thank You!

Please guide me to solve this problem.


@Embeddable
@MappedSuperclass
public class DBUniqueId implements Serializable {

/**
* serialVersionUID.
*/
private static final long serialVersionUID = 8903598739796209331L;
/**
* root.
*/
private String root;
/**
* extension.
*/
private String extension;
/**
* version.
*/
private String version;

//Getters & Setters

}



@Entity
@Table(name = "MyTable", schema = "MySchema")
public class DBUser implements Serializable {
/**
* unique user id.
*/
private DBUniqueId uniqueUserId;
/**
* Get the unique user id.
*
* @return <code>DBUniqueId</code> - unique person id
*/
@Embedded
@AttributeOverrides( {
@AttributeOverride(name = "root", column = @Column(name = "LUSR02_ID_ROOT", nullable = true, length = 50)),
@AttributeOverride(name = "extension", column = @Column(name = "LUSR02_ID_EXT", nullable = true, length = 50))
})
public DBUniqueId getUserId () {
return uniqueUserId;
}
/**
* set user unique id.
*
* @param uniqueId - unique id of the person
*/
public void setUserId (final DBUniqueId uniqueId) {
this.uniqueUserId = uniqueId;
}

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 14 2012
Added on Feb 9 2012
8 comments
4,620 views