Re: Strange Hibernate Behaviour

Ben Litchfield <[email protected]>
Newsgroups gmane.comp.java.ejb.middlegen.user
Message-ID <[email protected]>
You need to flush/commit the transaction for it to work!  Otherwise
nothing will be added to the database and no error will be thrown.

Ben




On Wed, 5 May 2004, Neo Gigs wrote:

> Hello,
>
> I had the following codes with does not show me any error at all and there is no updates/insert
> into the database:
>
> import java.sql.Connection;
> import java.sql.DriverManager;
> import java.sql.SQLException;
>
> import com.theta.code.Addrtyp;
>
> import net.sf.hibernate.HibernateException;
> import net.sf.hibernate.MappingException;
> import net.sf.hibernate.Session;
> import net.sf.hibernate.SessionFactory;
> import net.sf.hibernate.cfg.Configuration;
>
> public class InsertACodeTest {
>
> 	private static Configuration cfg = null;
> 	private static SessionFactory sf = null;
> 	private static Connection conn = null;
> 	private static Session se = null;
> 	private static Addrtyp at = null;
>
> 	public static void main(String[] args) {
> 		try {
> 			loadDBConnection();
> 			loadConfiguration();
> 			loadFactorySession();
> 			loadSession();
> 			testInsert();
> 		} catch (Exception e) {
> 			e.printStackTrace();
> 		} finally {
> 			System.gc();
> 		}
> 	}
>
> 	private static void loadConfiguration() throws MappingException {
> 		cfg = new Configuration().addFile("Addrtyp.hbm.xml");
> 	}
>
> 	private static void loadFactorySession() throws HibernateException {
> 		sf = cfg.buildSessionFactory();
> 	}
>
> 	private static void loadDBConnection()
> 		throws
> 			ClassNotFoundException,
> 			IllegalAccessException,
> 			InstantiationException,
> 			SQLException {
> 		String sJDBCdriver = "COM.ibm.db2.jdbc.app.DB2Driver";
> 		String sDBurl = "jdbc:db2:LOS_DB";
> 		String sUserID = "db2admin";
> 		String sPassword = "db2admin";
> 		Class.forName(sJDBCdriver).newInstance();
> 		conn = DriverManager.getConnection(sDBurl, sUserID, sPassword);
> 	}
>
> 	private static void loadSession() {
> 		se = sf.openSession(conn);
> 	}
>
> 	private static void testInsert() throws HibernateException {
> 		at = new Addrtyp();
> 		at.setCode("999");
> 		at.setDesc("test 999");
> 		at.setStatus("A");
> 		at.setDescEnglish("bla");
> 		se.saveOrUpdate(at);
> 	}
> }
> and the XML file is like this:
>
> <?xml version="1.0"?>
> <!DOCTYPE hibernate-mapping PUBLIC
>     "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
>     "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
>
> <hibernate-mapping>
> <!--
>     Created by the Middlegen Hibernate plugin
>
>     http://boss.bekk.no/boss/middlegen/
>     http://hibernate.sourceforge.net/
> -->
>
> <class
>     name="com.theta.code.Addrtyp"
>     table="CODE.ADDRTYP"
> >
>
>     <id
>         name="code"
>         type="java.lang.String"
>         column="CODE"
>     >
>         <generator class="assigned" />
>     </id>
>
>     <property
>         name="desc"
>         type="java.lang.String"
>         column="DESC"
>         length="50"
>     />
>     <property
>         name="status"
>         type="java.lang.String"
>         column="STATUS"
>         length="1"
>     />
>     <property
>         name="descEnglish"
>         type="java.lang.String"
>         column="DESC_ENGLISH"
>         length="100"
>     />
>
>     <!-- associations -->
>
> </class>
> </hibernate-mapping>
>
> Can anyone tell me whats wrong? All I could get is these 2 lines:
>
> log4j:WARN No appenders could be found for logger (net.sf.hibernate.cfg.Environment).
> log4j:WARN Please initialize the log4j system properly.
>
> Does these warning won't update/insert anything into the database?
>
> Thanks
>
> Neo
>
>
>
>
> __________________________________
> Do you Yahoo!?
> Win a $20,000 Career Makeover at Yahoo! HotJobs
> http://hotjobs.sweepstakes.yahoo.com/careermakeover
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by: Oracle 10g
> Get certified on the hottest thing ever to hit the market... Oracle 10g.
> Take an Oracle 10g class now, and we'll give you the exam FREE.
> http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
> _______________________________________________
> middlegen-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/middlegen-user
>


-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g. 
Take an Oracle 10g class now, and we'll give you the exam FREE. 
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.