-->
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: Standalone Hibernate application- throwing MappingException.
PostPosted: Wed Feb 16, 2005 3:28 pm 
Newbie

Joined: Wed Feb 16, 2005 2:56 pm
Posts: 1
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp


Using Hibernate Version 2

public class QueryApp2 {

static SessionFactory sessionFactory;

public static void main ( String [ ] args ) {

try {

Configuration config = new Configuration();
sessionFactory = config.configure().addClass(Teams.class).buildSessionFactory();

Session session = null;

session = sessionFactory.openSession();

List cds = session.find("from BAM01.TEAMS");

Iterator iter = cds.iterator();
while (iter.hasNext()) {
Teams cd = (Teams)iter.next();

System.out.println(cd.getName());

}
session.flush();
session.close();




} catch( Exception x ) {
x.printStackTrace();

}


} //end main


} //end QueryApp


hibernate.cfg.xml

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="connection.datasource">java:comp/env/jdbc/QDSN_MLB400B</property>
<property name="dialect">net.sf.hibernate.dialect.DB2400Dialect</property>
<property name="show_sql">false</property>
<mapping resource="Teams.hbm.xml"/>
</session-factory>
</hibernate-configuration>

Teams.hbm.xml

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="Teams"
table="BAM01.TEAMS">

<id name="Id" type="int" unsaved-value="0">
<column name="TEAM_ID"
sql-type="int"
not-null="true"/>
<generator class="increment"/>
</id>

<property name="name">
<column name="NAME"/>
</property>
</class>
</hibernate-mapping>

Teams.java


import java.io.*;
import java.util.*;

public class Teams {
int id;
String name;

public Teams() {
}

public Teams(String name) {
this.name = name;
}

public void setId(int id) {
this.id = id;
}

public int getId(){
return id;
}

public void setName(String name) {
this.name = name;
}

public String getName() {
return name;
}

}

hibernate.properties

hibernate.connection.driver_class = com.ibm.as400.access.AS400JDBCDriver
hibernate.connection.url = jdbc:as400://mlb400b.mydabasename.com
hibernate.connection.username = CHENG
hibernate.connection.passord = tom6922
hibernate.dialect = net.sf.hibernate.dialect.DB2400Dialect

all these files are unber root in windows C:\

when run this standalone hibernate app iam getting the following exception.

net.sf.hibernate.MappingException: Error reading resource: Teams.hbm.xml
at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:357)
at QueryApp2.main(QueryApp2.java:42)
Caused by: net.sf.hibernate.MappingException: duplicate import: Teams
at net.sf.hibernate.cfg.Mappings.addImport(Mappings.java:85)
at net.sf.hibernate.cfg.Binder.bindClass(Binder.java:127)
at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:222)
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

Please help me, i urgently need to finish my assignment, this is just the beginning where i am stuck.

Thanks for the help.

jsp


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 02, 2005 4:50 pm 
Newbie

Joined: Tue Mar 01, 2005 5:00 pm
Posts: 11
Hello, I exactly have the same problem with Hibernate 3 using Hibernate Tool 3 under Eclipse 3.1.m4.

All my files have been automaticly generated and placed by Hibernate Tool 3 execpt this:

Code:
public class principal {

   public static void main(String[] args) throws Exception {
      
         Cat gat = new Cat();
         gat.setId("id1");
         gat.setNom("caty");
      
         Configuration cfg = new Configuration();
         cfg.configure();
         cfg.addClass(Cat.class);
         SessionFactory sf = cfg.buildSessionFactory();
         Session sess = sf.openSession();
         Transaction t = sess.beginTransaction();
         sess.save(gat);
         t.commit();
         sess.close();
      }

}


Someone can help us?

Than you!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 02, 2005 5:06 pm 
Newbie

Joined: Tue Mar 01, 2005 5:00 pm
Posts: 11
Hello jspsai!

I had the same problem how you can see in previous post-reply and now I have resolved this error. I've a new error :-(.

The problem is that you (and I) ara mapping two times the same:

1) In hibernate.cfg.xml you has: "... <mapping resource="Teams.hbm.xml"/> ..."
2) In QueryApp2.java you has: "... config.configure().addClass(Teams.class).buildSessionFactory();..."

I've resolved my problem deleting "add.Class(...)".

Try!


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.