- This topic has 2 replies, 2 voices, and was last updated 19 years, 7 months ago by Jag2004.
-
AuthorPosts
-
Jag2004MemberI am running my first hibernate example using oracle thin drivers. It complied fine but when I run the Java application. it shows the following meesage.
localhost:3333 –> [2]
localhost:4444 –> [2]
localhost:1111 –> [1, 2, 3]
localhost:6767 –> [2]localhost:3333 –> [2]
localhost:4444 –> [2]
localhost:6767 –> [2]localhost:1111 –> [1, 2, 3, 4, 5, 6, 7, 8]
localhost:3333 –> [2]
localhost:4444 –> [2]
localhost:6767 –> [2]localhost:1111 –> [1, 2, 3, 4, 5, 6, 7, 8]
localhost:3333 –> [2]
localhost:4444 –> [2]
localhost:6767 –> [2]localhost:1111 –> [1, 2, 3, 5, 7]
localhost:3333 –> [2]
localhost:4444 –> [2]
localhost:6767 –> [2]Actually it should show “Save successful” or “Save failed”
shown below is the HibernateTest page
———————————————
package com.genuitec.ibernate;
import net.sf.hibernate.*;public class HibernateTest {
public static void main(String[] args) {
System.out.println(“b point 1”);
// Step 1 – Create a new entity
try {
DocumentType dt = new DocumentType();
// Step 2 – Set message field
dt.setDescription(“New Doctype”);
// Step 3 – Get a Hibernate Session
Session session = SessionManager.currentSession();
// Step 4 – Persist entity to database
Transaction tx = session.beginTransaction();
session.save(dt);
tx.commit();
System.out.println(“Save successful.”);
session.close();
} catch (HibernateException e) {
System.out.println(“Save failed.”);
} finally {
try {
// Step 5 – close the session
SessionManager.closeSession();
} catch (HibernateException e1) {
// do nothing
}
}
}
}shown below is the hibernated table called “DocumentType”, please note that document type table has 2 columns , doc_type_id and description.
/*
* Created Tue May 10 12:21:28 PDT 2005 by MyEclipse Hibernate Tool.
*/
package com.genuitec.ibernate;import java.io.Serializable;
/**
* A class that represents a row in the ‘DOCUMENT_TYPE’ table.
* This class may be customized as it is never re-generated
* after being created.
*/
public class DocumentType
extends AbstractDocumentType
implements Serializable
{
private String description;/**
* Simple constructor of DocumentType instances.
*/
public DocumentType()
{
}public void setDescription(String desc) {
this.description = desc;
}
/**
* Constructor of DocumentType instances given a simple primary key.
* @param docTypeId
*/
public DocumentType(java.lang.Short docTypeId)
{
super(docTypeId);
}/* Add customized code below */
}
here is the doumenttype.hbm.xml
<?xml version=”1.0″?>
<!DOCTYPE hibernate-mapping PUBLIC
“-//Hibernate/Hibernate Mapping DTD 2.0//EN”
“http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd” ><!– DO NOT EDIT: This is a generated file that is synchronized –>
<!– by MyEclipse Hibernate tool integration. –>
<!– Created Tue May 10 12:21:28 PDT 2005 –>
<hibernate-mapping package=”com.genuitec.ibernate”><class name=”DocumentType” table=”DOCUMENT_TYPE”>
<id name=”docTypeId” column=”DOC_TYPE_ID” type=”java.lang.Short”>
<generator class=”increment”/>
</id><property name=”description” column=”DESCRIPTION” type=”java.lang.String” not-null=”true” />
</class></hibernate-mapping>
Thanks for your help, in advance[url][/url]
Riyad KallaMemberHow exactly are you running the hibernate code? Are you running it as an application or from within a web application? Our code doesn’t generate any printouts that look like this…
Jag2004MemberThanks for your reply
I was running the Hibernate example on the myeclipse.comOnly change I made is to point to my local database and choose a table document_type. MOst of the code is generated by myeclipse IDE. I have added the following method in the DocumentType class
public void setDescription(String desc) {this.description = desc;
}
It is standalone java project.
Only this that I changed is
http://myeclipseide.com/enterpriseworkbench/help/index.jsp?topic=/com.genuitec.myeclipse.doc/html/quickstarts/hibernate/index.html -
AuthorPosts