-->
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.  [ 4 posts ] 
Author Message
 Post subject: tutorial error
PostPosted: Sat Jan 24, 2009 10:39 pm 
Newbie

Joined: Sat Jan 24, 2009 10:25 pm
Posts: 2
I have been trying to get the tutorial to work, but after section 1.2.6. i keep getting an error when i run the ant file.

Hibernate version:
3.3.1.GA

The error that i am getting is.

C:\Users\matt\Desktop\project>ant run -Daction=store
Buildfile: build.xml

clean:
[delete] Deleting directory C:\Users\matt\Desktop\project\bin
[mkdir] Created dir: C:\Users\matt\Desktop\project\bin

copy-resources:
[copy] Copying 3 files to C:\Users\matt\Desktop\project\bin

compile:
[javac] Compiling 3 source files to C:\Users\matt\Desktop\project\bin
[javac] C:\Users\matt\Desktop\project\src\events\Event.java:5: duplicate cla
ss: org.hibernate.tutorial.domain.Event
[javac] public class Event {
[javac] ^
[javac] C:\Users\matt\Desktop\project\src\events\EventManager.java:26: canno
t access events.Event
[javac] bad class file: C:\Users\matt\Desktop\project\src\events\Event.java
[javac] file does not contain class events.Event
[javac] Please remove or make sure it appears in the correct subdirectory of
the classpath.
[javac] Event theEvent = new Event();
[javac] ^
[javac] 2 errors

BUILD FAILED
C:\Users\matt\Desktop\project\build.xml:23: Compile failed; see the compiler err
or output for details.

Total time: 1 second

If any one could please help me it would be greatly appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 25, 2009 8:47 am 
Senior
Senior

Joined: Thu Jan 08, 2009 3:48 pm
Posts: 168
It says duplicate class, did you copy/paste one existing file and not change the class name?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 25, 2009 3:44 pm 
Newbie

Joined: Sat Jan 24, 2009 10:25 pm
Posts: 2
There is no copy's in my project folder, this is the file structure and the code from my tutorial project

+hibernate-tutorial
+data
+src
+events
Event.hbm.xml
Event.java
EventManager.java
+util
HibernateUtil.java
hibernate.cfg.xml
+lib
hsqldb.jar
hibernate3.jar
+bin
build.xml


build.xml

<project name="hibernate-tutorial" default="compile">

<property name="sourcedir" value="${basedir}/src"/>
<property name="targetdir" value="${basedir}/bin"/>
<property name="librarydir" value="${basedir}/lib"/>

<path id="libraries">
<fileset dir="${librarydir}">
<include name="*.jar"/>
</fileset>
</path>

<target name="clean">
<delete dir="${targetdir}"/>
<mkdir dir="${targetdir}"/>
</target>



<target name="compile" depends="clean, copy-resources">
<javac srcdir="${sourcedir}"
destdir="${targetdir}"
classpathref="libraries"/>
</target>

<target name="copy-resources">
<copy todir="${targetdir}">
<fileset dir="${sourcedir}">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>

<target name="run" depends="compile">
<java fork="true" classname="events.EventManager" classpathref="libraries">
<classpath path="${targetdir}"/>
<arg value="${action}"/>
</java>
</target>

</project>


hibernate.cfg.xml

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

<hibernate-configuration>

<session-factory>

<!-- Database connection settings -->
<property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="connection.url">jdbc:hsqldb:hsql://localhost</property>
<property name="connection.username">sa</property>
<property name="connection.password"></property>

<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>

<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>

<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>

<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>

<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>

<mapping resource="events/Event.hbm.xml"/>

</session-factory>

</hibernate-configuration>


Event.hbm.xml

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

<hibernate-mapping>

<class name="events.Event" table="EVENTS">
<id name="id" column="EVENT_ID">
<generator class="native"/>
</id>
<property name="date" type="timestamp" column="EVENT_DATE"/>
<property name="title"/>
</class>

</hibernate-mapping>


EventManager.java

package events;
import org.hibernate.Session;

import java.util.Date;

import util.HibernateUtil;

public class EventManager {

public static void main(String[] args) {
EventManager mgr = new EventManager();

if (args[0].equals("store")) {
mgr.createAndStoreEvent("My Event", new Date());
}

HibernateUtil.getSessionFactory().close();
}

private void createAndStoreEvent(String title, Date theDate) {

Session session = HibernateUtil.getSessionFactory().getCurrentSession();

session.beginTransaction();

Event theEvent = new Event();
theEvent.setTitle(title);
theEvent.setDate(theDate);

session.save(theEvent);

session.getTransaction().commit();
}

}

Event.java

package org.hibernate.tutorial.domain;

import java.util.Date;

public class Event {
private Long id;

private String title;
private Date date;

public Event() {}

public Long getId() {
return id;
}

private void setId(Long id) {
this.id = id;
}

public Date getDate() {
return date;
}

public void setDate(Date date) {
this.date = date;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}
}

HibernateUtil.java

package util;

import org.hibernate.*;
import org.hibernate.cfg.*;

public class HibernateUtil {

private static final SessionFactory sessionFactory;

static {
try {
// Create the SessionFactory from hibernate.cfg.xml
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}

public static SessionFactory getSessionFactory() {
return sessionFactory;
}

}


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2009 11:50 am 
Senior
Senior

Joined: Thu Jan 08, 2009 3:48 pm
Posts: 168
In your Event.hbm.xml it says:
Code:
<class name="events.Event" table="EVENTS">


this should probably just read
Code:
<class name="Event" table="EVENTS">

(there are cases when you have to enter the full package-path, but only with overlapping names i think)

hope that helps


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.