wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Can't persist data into Oracle 10g by the default persistence layer of EJB 3.0 (Hibernate) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Can Watch "Can New topic

Can't persist data into Oracle 10g by the default persistence layer of EJB 3.0 (Hibernate)

tan dung dang

Joined: Oct 09, 2008
Posts: 6
Hello pro,
I am trying to insert data into Oracle 10g but it is not successful. I had NO WARNING, NO ERRORS, but I STILL CAN'T persist an object :pissed: .

- User.java file
public class User implements Serializable {
private String username;
private String password;
private Long id;

public User() {

public User(String username, String password) {
this.username = username;
this.password = password;

public String getUsername() {
return username;
public String getPassword() {
return password;

public void setUsername(String username) {
this.username = username;
public void setPassword(String password) {
this.password = password;

public Long getId() {
return id;

public void setId(Long id) {
this.id = id;

- persistence.xml file:
<persistence-unit name="scbcdejb">
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
<property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver" />
<property name="hibernate.connection.username" value="dzungdev" />
<property name="hibernate.connection.password" value="dzungdev" />
<property name="hibernate.connection.url" value="jdbc:oracle:thin:dzungdev/dzungdev@" />
<property name="hibernate.show_sql" value="true"/>
<!--<property name="hibernate.max_fetch_depth" value="3" />


- orm.xml file:
<entity class="dzung.entity.User" access="PROPERTY">
<table name="M3_USER"></table>
<sequence-generator name="user_seq" sequence-name="M3_USER_SEQ"/>
<id name="id">
<column name="id" />
<generated-value strategy="SEQUENCE" generator="user_seq"/>
<basic name="password">
<column name="password" />
<basic name="username">
<column name="username" />

- This is Client.java file:

public class Client {
public static void main(String[] args) {
emf = Persistence.createEntityManagerFactory("scbcdejb");
EntityManager em = emf.createEntityManager();
try {
User u1 = new User("dzungdev", "test");
System.out.println("Go here");
} finally {

My console is display with: Hibernate: select M3_USER_SEQ.nextval from dual
Go here

NO ERROR, NO WARNING but when I go to the schema to see data, nothing in the M3_USER table.

Are there someone to give me an advice :(
Uppala Ramana

Joined: Jan 14, 2010
Posts: 14

You have to use transactions...to sync your persistent entities to databse.

}catch(Exception exception){


Ramana Uppala
tan dung dang

Joined: Oct 09, 2008
Posts: 6
Thank Uppala, now it runs well.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Can't persist data into Oracle 10g by the default persistence layer of EJB 3.0 (Hibernate)
Similar Threads
JPA /Hibernate mapping error
Sequence increment does not match its pre-allocation size.
problem with jsp:useBean tag
JPA /Hibernate mappiing error
transaction rollbacks, but a record is inserted?