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