-->
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.  [ 3 posts ] 
Author Message
 Post subject: Can't see the save data in DB
PostPosted: Sat Dec 16, 2006 6:17 pm 
Newbie

Joined: Sat Dec 16, 2006 6:10 pm
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
hibernate-annotations-3.2.0.GA
hibernate-entitymanager-3.2.1.GA

Mapping documents:
@Entity
@Table(name="ORGANIZATION")
@SequenceGenerator(name="SEQ_ORGANIZATION", sequenceName="ORG_SEQUENCE")

public class TSOrganization implements Serializable
{
/** A unique ID for this organization */
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SEQ_ORGANIZATION")
@Column(name="ORG_ID", nullable=false, length=10)
private Integer id;

/** Organization name */
@Column(name="NAME", length=50)
private String name;

/** Parent of this organization */
@OneToOne(cascade=CascadeType.ALL)
@JoinColumn(name="PARENT_ORG_ID", referencedColumnName="ORG_ID", nullable=true)
@ForeignKey(name="FK_PARENT_ORG")
private TSOrganization parent;

public TSOrganization()
{
}

public String getName()
{
return name;
}

public void setName(String pName)
{
this.name = pName;
}

public Integer getId()
{
return id;
}

public void setId(Integer id)
{
this.id = id;
}

public TSOrganization getParent()
{
return parent;
}

public void setParent(TSOrganization pParent)
{
this.parent = pParent;
}

/**
* If a parent exists then there exists a child
* @return true if parent exists
*/
public boolean isChild()
{
if ( parent != null )
{
return true;
}

return false;
}
}

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/ ... ce_1_0.xsd"
version="1.0">
<persistence-unit name="tms" transaction-type="RESOURCE_LOCAL">
<properties>
<property name="hibernate.archive.autodetection" value="class" />

<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="use_sql_comments" value="true" />

<!-- JDBC connection properties -->
<property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver" />
<property name="hibernate.connection.url" value="jdbc:oracle:thin:@xxxxxx" />
<property name="hibernate.connection.username" value="xxxxxx" />
<property name="hibernate.connection.password" value="xxxxxx" />

<property name="hibernate.dialect" value="org.hibernate.dialect.OracleDialect" />
</properties>
</persistence-unit>
</persistence>

EntityManager em = persistenceMgr.getEntityManager();
EntityTransaction tx = null;

try
{
tx = persistenceMgr.getEntityManager().getTransaction();

tx.begin();
em.persist(org);
tx.commit();
}
catch ( RuntimeException rte )
{
handleException(rte, methodName, tx);
}
catch ( Exception e )
{
handleException(e, methodName, tx);
}
catch ( Throwable e )
{
handleException(e, methodName, tx);
}
finally
{
em.close();
}

and the main driver that create TSOrganization
TSOrganizationDAO orgDAO = new TSOrganizationDAO();

TSOrganization parentOrg = new TSOrganization();
parentOrg.setName("ABC Software HQ");
orgDAO.makePersist(parentOrg);

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs: I don't see any exception

Name and version of the database you are using: 10g

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject: You are using the wron instance of the entity manager!
PostPosted: Sat Dec 16, 2006 6:50 pm 
Newbie

Joined: Sat Dec 16, 2006 6:43 pm
Posts: 1
Hello T!

Sorry, I was not able to help you yesterday. I was busy fixing tea for everybody! ;)

Anyway, I think your problem is easy. You are using a different instance of the entity manager when you are trying to get a transaction object!!

So, instead of this

Code:
EntityManager em = persistenceMgr.getEntityManager();
EntityTransaction tx = null;

try
{
tx = persistenceMgr.getEntityManager().getTransaction();

tx.begin();
em.persist(org);
tx.commit();
}


Do this:

Code:
EntityManager em = persistenceMgr.getEntityManager();
EntityTransaction tx = null;

try
{
tx = em.getTransaction();

tx.begin();
em.persist(org);
tx.commit();
}


Let me know if it works for you!

Cheers,


Top
 Profile  
 
 Post subject: It's working now..
PostPosted: Sat Dec 16, 2006 11:25 pm 
Newbie

Joined: Sat Dec 16, 2006 6:10 pm
Posts: 2
Thanks, it is working and I overlooked what I did.


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

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.