EJB3 - @Column (insertable = "false") question

I am building a J2SE application with EJB3 and DB Express Express.

My problem is that I am installing an EntityBean in my project that matches the table in the database. The table contains a column that is not null and has a default value . All I want is that when saving new data to this table using EJB, the column value will get its default value. This is how I installed it in the project:

//holds user first name
@Basic(optional = true)
@Column(name = "FIRST_NAME", insertable = false, updatable = true, nullable = false)
private String m_firstName;

I also installed it in the ORM.XML file:

    <basic name="firstName">
        <column name="FIRST_NAME" insertable="false" updatable="true" nullable="false"/>
    </basic>

But for some reason, creating a new EntityBean and not setting the first name field, and then trying to save 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")

This means that the save manager is trying to insert the first name field, although I told him not to.

- ?

!

+5
4

:

@Basic(optional = false)
@Column(name = "FIRST_NAME", insertable = false, updatable = true, nullable = false)
private String m_firstName;

FIRST_NAME SQL. , TopLink Essentials, GlassFish. , , № 627 ( " insertable = false updatable = false" ). , , :

  • private String m_firstName = "my database default"; (, ) - -
  • ( OpenJPA, Hibenate)
+1

. null Hibernates SQL

@Entity
@Table(name = "your_table")
@org.hibernate.annotations.Entity(
  dynamicInsert = true
)
public class YourClass{


}
+1

TopLink Essentials , insertable, updateable = false.

EclipseLink, .

http://www.eclipse.org/eclipselink/

+1

@Basic(optional = true), NULLABLE ( )?

, .

0

All Articles