-->
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: could not load by id error
PostPosted: Wed Jun 16, 2004 7:58 pm 
Beginner
Beginner

Joined: Thu Oct 23, 2003 1:17 pm
Posts: 44
I've been procrastinating posting this, since I'm sure it's a stupid mistake, but I can't figure out the answer.

I'm trying to do a simple inheritence example, I'm using Hibernate 2.1.4 and with MySQL.

I'm using the HibernateUtil as suggested in the first chapter of the docs.

I have a Product class, with some basic stuff on it, and I have a Book class, that extends Product.

my mapping looks like this:

Code:
<?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 package="simple">
    <class name="Product" table="products">
        <id name="productId" column="id" type="long">
            <generator class="identity"/>
        </id>
        <property name="price" type="float"/>
        <property name="name"/>
        <property name="description"/>

        <joined-subclass name="Book" table="books">
            <key column="product_id" foreign-key="id" />
            <property name="isbn" type="string"/>
        </joined-subclass>


    </class>
</hibernate-mapping>


My main code looks like this:
Code:
       
        Session session = HibernateUtil.currentSession();
        Product p = (Product) session.load(Product.class, new Long(2));
        System.out.println(p);
        HibernateUtil.closeSession();


I'm just trying to print out a product that I have in the database.
If I comment out the book mapping, it works great. When I have it uncommented like above, I get these errors
Code:
SEVERE: Syntax error or access violation,  message from server: "You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near '(product0__1_.product_id is not null, 1,  casewhen(product0_.id"
Jun 16, 2004 7:51:11 PM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 1064, SQLState: 42000
Jun 16, 2004 7:51:11 PM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Syntax error or access violation,  message from server: "You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near '(product0__1_.product_id is not null, 1,  casewhen(product0_.id"
Jun 16, 2004 7:51:11 PM net.sf.hibernate.JDBCException <init>
SEVERE: could not load by id: [simple.Product#2]
java.sql.SQLException: Syntax error or access violation,  message from server: "You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near '(product0__1_.product_id is not null, 1,  casewhen(product0_.id"
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1977)
   at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1163)
   at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1272)
   at com.mysql.jdbc.Connection.execSQL(Connection.java:2236)
   at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1555)
   at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)
   at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:800)
   at net.sf.hibernate.loader.Loader.doQuery(Loader.java:189)
   at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
   at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:836)
   at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:856)
   at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:59)
   at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:51)
   at net.sf.hibernate.persister.NormalizedEntityPersister.load(NormalizedEntityPersister.java:405)
   at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2113)
   at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1987)
   at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1916)
   at simple.Main.doLoad(Main.java:39)
   at simple.Main.main(Main.java:51)
net.sf.hibernate.JDBCException: could not load by id: [simple.Product#2]
   at net.sf.hibernate.persister.NormalizedEntityPersister.load(NormalizedEntityPersister.java:413)
   at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2113)
   at net.sf.hibernate.impl.SessionImpl.doLoadByClass(SessionImpl.java:1987)
   at net.sf.hibernate.impl.SessionImpl.load(SessionImpl.java:1916)
   at simple.Main.doLoad(Main.java:39)
   at simple.Main.main(Main.java:51)
Caused by: java.sql.SQLException: Syntax error or access violation,  message from server: "You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near '(product0__1_.product_id is not null, 1,  casewhen(product0_.id"
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1977)
   at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1163)
   at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1272)
   at com.mysql.jdbc.Connection.execSQL(Connection.java:2236)
   at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1555)
   at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)
   at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:800)
   at net.sf.hibernate.loader.Loader.doQuery(Loader.java:189)
   at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
   at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:836)
   at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:856)
   at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:59)
   at net.sf.hibernate.loader.EntityLoader.load(EntityLoader.java:51)
   at net.sf.hibernate.persister.NormalizedEntityPersister.load(NormalizedEntityPersister.java:405)
   ... 5 more


Any idea what's going on? I'm not even trying to get a Book, but having that mapping in there screws everything up.

Thanks in advance for any suggestions.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 17, 2004 8:05 pm 
Beginner
Beginner

Joined: Thu Oct 23, 2003 1:17 pm
Posts: 44
anyone?

Can someone at least tell me if it looks like I'm heading in the right direction? Does my mapping look right?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 20, 2004 8:19 am 
Beginner
Beginner

Joined: Thu Oct 23, 2003 1:17 pm
Posts: 44
My problem was in my hibernate.properties, I'm using MySQL, but I had the wrong dialect set.

Code:
hibernate.dialect=net.sf.hibernate.dialect.HSQLDialect


when it should've been

Code:
hibernate.dialect = net.sf.hibernate.dialect.MySQLDialect


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.