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.