EJB3 - @Column(insertable="false") question
Posted
by WhiteTigerK
on Stack Overflow
See other posts from Stack Overflow
or by WhiteTigerK
Published on 2010-02-05T23:06:37Z
Indexed on
2010/04/25
20:43 UTC
Read the original article
Hit count: 599
Hi All,
I'm building a J2SE application with EJB3 and an Oracle Express Edition DB.
My problem is like that - I set an EntityBean in my project which matches a table in the DB. The table contains a column which is not nullable and has a default value. All I want is that when persisting a new data to this table using the EJB, the column's value will get its default value. This is how I set it in the project:
//holds user's first name
@Basic(optional = true)
@Column(name = "FIRST_NAME", insertable = false, updatable = true, nullable = false)
private String m_firstName;
I also set it in the ORM.XML file:
<basic name="firstName">
<column name="FIRST_NAME" insertable="false" updatable="true" nullable="false"/>
</basic>
But for some reason, when creating a new EntityBean and not setting the first name field, and then trying to persist it, i get the following exception:
Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.1 (Build b60e-fcs (12/23/2008))): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: ORA-01400: cannot insert NULL into ("TSDB"."USERS"."FIRST_NAME")
Which means that the persistence manager tries to insert the first name field although I told it not to.
Am I doing something wrong here ?
Thanks!
© Stack Overflow or respective owner