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.  [ 3 posts ] 
Author Message
 Post subject: A quite strange problem with MS SQL Server.
PostPosted: Mon Aug 15, 2005 12:45 am 
Newbie

Joined: Sun Aug 14, 2005 6:07 am
Posts: 14
Location: China
I use MS SQL Server as my datastore.

I have deployed my JNDI,JDBC in my webcontainer:Tomcat5.0.

This is the deploy details:

JNDI Name: jdbc/testDB

Data Source URL: jdbc:microsoft:sqlserver://127.0.0.1:1433;databaseName=Hibernate

JDBC Driver Class: com.microsoft.jdbc.sqlserver.SQLServerDriver


And this is my Servlet:

Code:
package net.hibernate.quickstart;

import javax.servlet.*;
import javax.servlet.http.*;
import net.sf.hibernate.*;
import net.sf.hibernate.cfg.*;

public class SaveCats extends HttpServlet {
  public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,java.io.IOException {
    doPost(request,response);
  }
  public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,java.io.IOException {
    try {
      // Session session = HibernateUtil.currentSession();
      SessionFactory sf = new Configuration().configure().buildSessionFactory();
      Session session = sf.openSession();

      Transaction tx= session.beginTransaction();

      Cat princess = new Cat();
      princess.setName("Princess");
      princess.setSex('F');
      princess.setWeight(7.4f);

      session.save(princess);
      tx.commit();

      HibernateUtil.closeSession(); 
    }
    catch(HibernateException he) {
     // response.getWriter().print("Exception: " + he);
      he.printStackTrace(response.getWriter());
    }
  }


When i run the servlet,it thrown exceptions:

net.sf.hibernate.JDBCException: could not insert: [net.hibernate.quickstart.Cat#297e3afc05b86a340105b86a3a840001]
...
Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Invalid object name 'Cat'.
...


This tell me, the table Cat is not vaild,I checked my Cat.hbm.xml,it's correct.So, i copy my Cat.db in a database named Hibernate to the default example database Northwind in MS SQL Server.

Then i run my servlet again,this time,a record insert to Northwind.Cat correctly?

I feel quite strange,I have set my JNDI JDBC URL to:
jdbc:microsoft:sqlserver://127.0.0.1:1433;databaseName=Hibernate
With a specific database Hibernate.
But why the hibernate find the Cat in Northwind?

Can u help me?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 04, 2006 7:18 pm 
Newbie

Joined: Fri Sep 02, 2005 6:03 pm
Posts: 13
imwaiting,

I have the same issue. I've created a simple table to test with in SQLServer and am having no luck accessing it. My mapping file was generated using the eclipse plugin and I'm pretty sure it's correct. Funny, the hibernate stuff I'm doing with PostGreSQL works flawlessly.

Anyway, I can access the table and get rows with createSqlQuery via my hibernate session. However, when I try to use HQL, I get a MappingException ("unknown entity"). How does this compare to what you're seeing?

Can you post your mapping file so we can have a look? Here's my mapping file so you can compare:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--
        Auto-generated mapping file from
        the hibernate.org cfg2hbm engine
-->
    <class name="cypress.data.FormNumber" table="form_number" schema="dbo" catalog="form_tracker">
        <id name="recId" type="integer">
            <column name="rec_id" />
            <generator class="assigned" />
        </id>
        <property name="person" type="string">
            <column name="person" length="40" />
        </property>
        <property name="form" type="string">
            <column name="form" length="20" />
        </property>
    </class>
</hibernate-mapping>


Be sure and post how you fixed this if you have.

--Kurt


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 04, 2006 7:38 pm 
Newbie

Joined: Fri Sep 02, 2005 6:03 pm
Posts: 13
Fixed:

I didn't have my hbm.xml file reference as a mapping file withing the cfg.xml file.

Code:
            <mapping resource="cypress/data/FormNumber.hbm.xml" />


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