| 
					
						 Hibernate version: 
 2.1.6
 Mapping documents:
 
 Code between sessionFactory.openSession() and session.close():
 
 Full stack trace of any exception that occurs:
 
 Name and version of the database you are using:
 MySql 4.1.1 alpha
 The generated SQL (show_sql=true):
 
 Debug level Hibernate log excerpt:
 
 Hi all,
    i am using Hibernate together with Spring and i am trying to insert values into my databasae.
 my Entry.hbm.xml is as follows
 
 <?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>
     <class
         name="com.myapp.hibernate.HibernateEntry"
         table="entries"
         dynamic-update="false"
         dynamic-insert="false"
     >
 
         <id
             name="id"
             column="id"
             type="int"
             unsaved-value="0"
         >
             <generator class="increment">
             </generator>
         </id>
 
         <property
             name="date"
             type="java.util.Date"
             update="true"
             insert="true"
             column="date"
         />
 
         <property
             name="description"
             type="java.lang.String"
             update="true"
             insert="true"
             column="description"
         />
 
         <property
             name="type"
             type="int"
             update="true"
             insert="true"
             column="type"
         />
 
         <property
             name="amount"
             type="double"
             update="true"
             insert="true"
             column="amount"
         />
 
         <property
             name="user"
             type="java.lang.String"
             update="true"
             insert="true"
             column="user"
         />
 
         <!--
             To add non XDoclet property mappings, create a file named
                 hibernate-properties-HibernateEntry.xml
             containing the additional properties and place it in your merge dir.
         -->
 
     </class>
 
         <query name="TypeQuery"><![CDATA[
             from com.myapp.hibernate.HibernateEntry e WHERE e.type = ? and e.user = ? order by e.date asc 
         ]]></query>
         <query name="DateQuery"><![CDATA[
             from com.myapp.hibernate.HibernateEntry e WHERE e.user = ? and e.date >= ? and e.date <=? order by e.date asc 
         ]]></query>
         <query name="DateTypeQuery"><![CDATA[
             from com.myapp.hibernate.HibernateEntry e WHERE e.type = ? and e.user = ? and e.date >= ? and e.date <=? order by e.date asc
         ]]></query>
 
 </hibernate-mapping>
 
 i am using following code (thru Spring)for inserting values into database..
 
 public void insert(Entry data) throws PersistenceException {
 		try {
 			_log.error("INSERTING ENTRY...:" + data.getDescription());
 			
 			getHibernateTemplate().saveOrUpdate(data);
 		} catch(Exception e) {
 			_log.error("Exception in creating HibernateEntry\n" + e);
 			
 			throw  new PersistenceException(e);
 		} 
 	}
 
 
 in my test i am calling this method,  and whenever this gets called all the 'hibernate related tables' are emptied..
 i cannot figure out why....
 
 below is the code of my test class
 
 public class BaseHibernateTest extends MenagerieTest {
 
     private AbstractApplicationContext context;
 
     private Log log = LogFactory.getLog(getClass());
 
     private static Map applicationContextCache = new HashMap();
 
     protected PersistenceManager manager;	
 
     protected final ApplicationContext getContext() {
         return context;
     }
 
 
     protected static ApplicationContext appContext = null;
 
     static {
 	  appContext = new ClassPathXmlApplicationContext("/applicationContext.xml");
     }
 
     public void setUp()  {
 	try {
 		//appContext = new ClassPathXmlApplicationContext("/applicationContext.xml");
         	manager = (PersistenceManager)appContext.getBean("persistenceManager");
 	} catch(Exception e) {
 		System.err.println("EXCEPTION IN SETUP\n" + e);
 	}
     }
 
     public void tearDown() {
 	try {
 		super.tearDown();
 	} catch(Exception e) {
 	    System.err.println("Exception in BaseHibernateTest.tearDown()\n" + e);
 	}
     }
 
     public void testCreateEntry() {
 	try {
 		Entry entry = getEntry();
 		manager.insert(entry);
 		System.err.println("Entry  created..");
                 
 		Object[] paramValues = new Object[]{new Integer("100"),"TestUser"};
 		Collection coll = manager.query("TypeQuery", paramValues);
 		assertEquals("Testing results size",coll.size(),1);
 		Iterator i = coll.iterator();		
 		while( i.hasNext()) {
 		     Entry found = (Entry)i.next();
 		     System.err.println("FOUND ENTRY:" + found);
 		     manager.delete(found);
 		}
 		System.err.println("************* TEST SUCCESSFUL!!!!");
 		
 	} catch(Exception e) {
 		System.err.println("Exception in testCreateEntry!\n" + e);
 		fail();
 	}
     }
 
     private Entry getEntry() {
 	Entry entry = manager.getEmptyEntry();
 	entry.setDescription("TestExpense");
 	Date date = new Date();
 	System.err.println("a today date is"+date);
 	entry.setDate(new Date());
 	entry.setType(100);
 	entry.setAmount(2.0);
 	entry.setUser("TestUser");
 	return entry;
     }
 
 }
 
 
 
 anyone can help?
 
 thanx in advance and regards
    marco 
					
  
						
					 |