I want to get the children of the Mother with the max name...
I can do a work around by getting the max from mother first, then getting her children, but I want to find out why the inner join is not working.
Thanks.
Hibernate version: 3.0
Mapping documents:
<!--MOTHER-->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class
name="onetomany.Mother"
table="Mother">
<id name="id"
column="id"
type="java.lang.Long">
<generator class="native"></generator>
</id>
<property
name="name"
type="java.lang.String"
update="true"
insert="true"
column="name"/>
<list
name="children"
lazy="false"
cascade="save-update">
<key
column="FK_ONE"
>
</key>
<index
column="MANY_INDEX"
/>
<one-to-many
class="onetomany.Children"
/>
</list>
</class>
</hibernate-mapping>
<!--CHILDREN-->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping
>
<class
name="onetomany.Children"
table="Children">
<id
name="id"
column="id"
type="java.lang.Long">
<generator class="native"></generator>
</id>
<property
name="name"
type="java.lang.String"
update="true"
insert="true"
column="name" />
</class>
<query name="getSomeone"><![CDATA[
SELECT max(b.name) FROM Children a INNER JOIN onetomany.Mother b
]]></query>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Query q=s.getNamedQuery("getSomeone");
List l=q.list();
Full stack trace of any exception that occurs:
Initial SessionFactory creation failed.java.lang.NullPointerException
java.lang.ExceptionInInitializerError
at util.HibernateUtil.<clinit>(HibernateUtil.java:16)
at onetomany.Join.main(Join.java:13)
Caused by: java.lang.NullPointerException
at org.hibernate.hql.ast.HqlSqlWalker.createFromJoinElement(HqlSqlWalker.java:264)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.joinElement(HqlSqlBaseWalker.java:3022)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:2841)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2719)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:513)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:371)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:201)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:151)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:427)
at org.hibernate.impl.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:388)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:291)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1005)
at util.HibernateUtil.<clinit>(HibernateUtil.java:13)
... 1 more
Exception in thread "main"
Name and version of the database you are using: MYSQL 5.0.16
The generated SQL (show_sql=true):NA
Debug level Hibernate log excerpt:
using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/myhibernate
connection properties: {user=, password=}
schema export complete
cleaning up connection pool: jdbc:mysql://localhost/myhibernate
Checking 1 named queries
|