-->
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: Got to be a stupid error
PostPosted: Tue Jun 28, 2005 8:04 am 
Newbie

Joined: Tue Apr 06, 2004 9:39 am
Posts: 5
I am getting the below errors when I try and run the below code. Very strange.

If I change the code to just:

configuration.addClass(Team.class);

and try and read a Team object from a Session it works - it just doesn't work if I use Team and Game at the same time.

Version:
2.1.7

Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping
>
<class
name="uk.co.smitek.league.Game"
table="GAME"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
optimistic-lock="version"
>

<id
name="id"
column="id"
type="java.lang.Long"
>
<generator class="increment">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Game.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>

<property
name="homeTeam"
type="uk.co.smitek.league.Team"
update="true"
insert="true"
access="property"
column="home_team_id"
/>

<property
name="homeTeamScore"
type="int"
update="true"
insert="true"
access="property"
column="home_team_score"
/>

<property
name="awayTeamScore"
type="int"
update="true"
insert="true"
access="property"
column="away_team_score"
/>

<property
name="kickoff"
type="java.util.Date"
update="true"
insert="true"
access="property"
column="date"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Game.xml
containing the additional properties and place it in your merge dir.
-->

</class>

</hibernate-mapping>


<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping
>
<class
name="uk.co.smitek.league.Team"
table="TEAM"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
optimistic-lock="version"
>

<id
name="id"
column="id"
type="java.lang.Long"
>
<generator class="increment">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Team.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>

<property
name="teamName"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="name"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Team.xml
containing the additional properties and place it in your merge dir.
-->

</class>

</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():

public static void main(String[] args) throws HibernateException, IOException
{

Configuration configuration = new Configuration();

configuration.addClass(Game.class).addClass(Team.class);

SessionFactory factory = configuration.buildSessionFactory();

Session session = factory.openSession();

Game game = (Game) session.load(Game.class, new Long("1"));

System.out.println(game);

session.close();
}

Full stack trace of any exception that occurs:
(cfg.Environment 478 ) Hibernate 2.1.7
(cfg.Environment 512 ) loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=com.mysql.jdbc.Driver, hibernate.cglib.use_reflection_optimizer=true, hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect, hibernate.connection.username=root, hibernate.connection.url=jdbc:mysql://localhost:3306/martin?autoReconnect=true, hibernate.show_sql=false, hibernate.connection.password=root, hibernate.connection.pool_size=20, hibernate.statement_cache.size=6}
(cfg.Environment 538 ) using CGLIB reflection optimizer
(cfg.Environment 567 ) using JDK 1.4 java.sql.Timestamp handling
(cfg.Configuration 350 ) Mapping resource: uk/co/smitek/league/Game.hbm.xml
(cfg.Binder 230 ) Mapping class: uk.co.smitek.league.Game -> GAME
(cfg.Configuration 255 ) Could not compile the mapping document
net.sf.hibernate.MappingException: Could not interpret type: uk.co.smitek.league.Team
at net.sf.hibernate.cfg.Binder.getTypeFromXML(Binder.java:935)
at net.sf.hibernate.cfg.Binder.bindSimpleValue(Binder.java:436)
at net.sf.hibernate.cfg.Binder.propertiesFromXML(Binder.java:1048)
at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:363)
at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1257)
at net.sf.hibernate.cfg.Configuration.add(Configuration.java:252)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:288)
at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:354)
at uk.co.smitek.league.dao.hibernate.Main.main(Main.java:30)
Exception in thread "main" net.sf.hibernate.MappingException: Error reading resource: uk/co/smitek/league/Game.hbm.xml
at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:357)
at uk.co.smitek.league.dao.hibernate.Main.main(Main.java:30)
Caused by: net.sf.hibernate.MappingException: Could not interpret type: uk.co.smitek.league.Team
at net.sf.hibernate.cfg.Binder.getTypeFromXML(Binder.java:935)
at net.sf.hibernate.cfg.Binder.bindSimpleValue(Binder.java:436)
at net.sf.hibernate.cfg.Binder.propertiesFromXML(Binder.java:1048)
at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:363)
at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1257)
at net.sf.hibernate.cfg.Configuration.add(Configuration.java:252)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:288)
at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:354)
... 1 more



Name and version of the database you are using:
MySQL 4.1

The generated SQL (show_sql=true):
Don't get this far!

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 28, 2005 8:56 am 
Regular
Regular

Joined: Thu Apr 29, 2004 5:08 pm
Posts: 56
Location: Montreal, Quebec, Canada
Code:
<property
name="homeTeam"
>>type="uk.co.smitek.league.Team"
update="true"
insert="true"
access="property"
column="home_team_id"
/>


You cannot do that. homeTeam isn`t a property (a property is of a primitive type, you cannot pass an entity class here).

What you really want is a one-to-one.

_________________
- Frank


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 28, 2005 9:39 am 
Newbie

Joined: Tue Apr 06, 2004 9:39 am
Posts: 5
So I was right. It was a stupid error. Not done Hibernate for a while, better dig out my book.

Thanks for your help Frank.


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.