-->
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.  [ 5 posts ] 
Author Message
 Post subject: net.sf.hibernate.JDBCException: could not insert:
PostPosted: Fri Jun 18, 2004 10:26 am 
Senior
Senior

Joined: Fri Jun 18, 2004 10:17 am
Posts: 140
Hi Guys,

I have used Hibernate for the first time today and have gotten quite far :) Excellent piece of kit.

I have 2 classes Schedules and DataAcquisitionSchedules. The latter extends the former. I wanted this to go into per-class and used a joined-subclass.

My configuration was successful in creating the 2 tables but when it tries to insert into the table with test values the following error occurs:

net.sf.hibernate.JDBCException: could not insert: [com.qas.newmedia.intranet.iq.dto.schedules.DataAcquisitionSchedule] could not insert:

VERSION
======
Hibernate: 2.1

MAPPING
======

Code:
<hibernate-mapping>

    <class name="com.qas.newmedia.intranet.iq.dto.schedules.Schedule" table="Schedules">

        <id name="id" type="long" column="schedule_id">
           <generator class="identity" />
       </id>
            
        <property name="status" column="status" not-null="true" />
      <property name="title" column="title" not-null="true" />
      <property name="summary" column="summary" not-null="true" />
      <property name="description" column="description" not-null="true" />
      <property name="created" type="date" column="created" not-null="true" />
      <property name="lastUpdated" type="date" column="last_updated" not-null="false" />

      <joined-subclass
         name="com.qas.newmedia.intranet.iq.dto.schedules.DataAcquisitionSchedule"
         table="DataAcquisitionSchedules">
         
           <key column="schedule_id" />
         
         <property name="productName" column="productName" not-null="true" />
         <property name="productRelease" column="productRelease" not-null="true" />

       </joined-subclass>

    </class>

</hibernate-mapping>


JAVA
===

Code:
Session session = HibernateUtil.currentSession();   
         Transaction tx = session.beginTransaction();
   
         DataAcquisitionSchedule schedule = new DataAcquisitionSchedule();
         schedule.setTitle("Test");
         schedule.setCreated(new Date());
         schedule.setDescription("Test Desc");
         schedule.setStatus("Test Stat");
         schedule.setSummary("Test Summ");
         schedule.setProductName("P Name");
         schedule.setProductRelease("4");
   
         session.save(schedule);
         tx.commit();
         HibernateUtil.closeSession();


DATABASE
=======

SQL Server 2000


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 18, 2004 12:17 pm 
Senior
Senior

Joined: Fri Jun 18, 2004 10:17 am
Posts: 140
OK, I have turned on sql logging ;) The insert is

Code:
Hibernate: insert into schedules.Schedules (status, title, summary, description, created, last_updated) values (?, ?, ?, ?, ?, ?)


I had set hibernate.default_schema to the wrong database!

Oops!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 21, 2004 8:09 am 
Senior
Senior

Joined: Fri Jun 18, 2004 10:17 am
Posts: 140
Hi again, OK well, I thought the schema thing was the problem but it still does not insert into the tables. The error thrown in the code is

Code:
net.sf.hibernate.JDBCException: could not insert: [com.qas.newmedia.intranet.iq.dto.schedules.DataAcquisitionSchedule] could not insert: [com.qas.newmedia.intranet.iq.dto.schedules.DataAcquisitionSchedule]


and in the stdout logging reports only

Code:
Hibernate: insert into dbSchedules.Schedules (status, title, summary, description, created, last_updated) values (?, ?, ?, ?, ?, ?)


dbSchedules.Schedules is correct for the database and table name. The insert looks fine too. All the values are set in my code which you can see in my first post.

Thanks if you can help!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 21, 2004 9:03 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Try executing the query manually and see if it works.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 21, 2004 9:20 am 
Senior
Senior

Joined: Fri Jun 18, 2004 10:17 am
Posts: 140
:) OK, I am getting an invalid object error from SQL Server for dbSchedules.Schedules

My JNDI JDBC URL specifies my database name dbSchedules and therefore when Hibernate appends Schedules table it forms the reference

dbSchedules.Schedules

which is not working. Normally I set my database with connection.setCatalog so I have not seen this before.

I suppose this is now an SQL Server problem to solve but if anyone else can explain why SQL Server likes

dbSchedules.dbo.Schedules

but not

dbSchedules.Schedules

I would appreciate it! I tried pushing dbSchedules.dbo into my JNDI JDBC URL connection but that did not work

Thanx!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.