-->
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.  [ 6 posts ] 
Author Message
 Post subject: Error message:An AnnotationConfiguration instance....
PostPosted: Mon Mar 21, 2005 1:54 pm 
Beginner
Beginner

Joined: Mon Mar 21, 2005 1:39 pm
Posts: 28
Hallo,
I hope you can help me.
I always get the error message: An AnnotationConfiguration instance is required to use <mapping package="contacts"/>


Hibernate version:
Hibernate3rc1
Hibernate Annotations 3.0 alpha 3


Mapping documents:hibernate.cfg.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE hibernate-configuration PUBLIC
   "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
   "C:/Uni/SS_05/Programmierpraktikum/workspace/hibernating/lib/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
   <session-factory>
   
      <!-- properties -->
      
      <property name="hibernate.connection.driver_class">
         com.mysql.jdbc.Driver
      </property>
      <property name ="hibernate.connection.url">
         jdbc:mysql://127.0.0.1/praktikum
      </property>
      <property name ="hibernate.connection.username">root</property>
      <property name ="hibernate.dialect">
         org.hibernate.dialect.MySQLDialect
      </property>      
      <property name="hibernate.connection.pool_site">
         4
      </property>
      <property name ="hibernate.show_sql">
         true
      </property>
      
      <!-- mapping files -->
      <mapping package="contacts"/>
      <mapping class="contacts.ContactInfo"/>
      
   </session-factory>
</hibernate-configuration>


Code between sessionFactory.openSession() and session.close():
Code:
public static void main(String[] args) throws HibernateException,
         SQLException {
       
      Configuration config = new Configuration();
      config.configure();

      // update database schema if required
      new SchemaUpdate(config).execute(true, true);

      //create session
      Session session = HibernateUtil.currentSession();

      //examples of using database with Contacts
      //examplesContact(session);

      //exapmles of using database with Folders
      examplesFolder(session);

      // close Session
      HibernateUtil.closeSession();
      System.exit(0);
   }


And thats class HibernateUtil

Code:
package main;

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

public class HibernateUtil {

    private static final SessionFactory sessionFactory;

    static {
        try {
            // Create the SessionFactory
            sessionFactory = new AnnotationConfiguration().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 final ThreadLocal session = new ThreadLocal();

    public static Session currentSession() throws HibernateException {
        Session s = (Session) session.get();
        // Open a new Session, if this Thread has none yet
        if (s == null) {
            s = sessionFactory.openSession();
            session.set(s);
        }
        return s;
    }

    public static void closeSession() throws HibernateException {
        Session s = (Session) session.get();
        session.set(null);
        if (s != null)
            s.close();
    }
}



Full stack trace of any exception that occurs:
30 INFO - configuring from resource: /hibernate.cfg.xml
30 INFO - Configuration resource: /hibernate.cfg.xml
Exception in thread "main" org.hibernate.MappingException: An AnnotationConfiguration instance is required to use <mapping package="contacts"/>
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1388)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1353)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1335)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1302)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1230)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1216)
at main.Shell.main(Shell.java:35)



Regards
Martin


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 23, 2005 7:35 am 
Beginner
Beginner

Joined: Mon Mar 21, 2005 1:39 pm
Posts: 28
Hallo again,
can't anybody really help me?

Regards
Martin


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 23, 2005 12:04 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
why dont you read the stacktrace ? ;)

you are instantiating a Configuration and the stacktrace clearly states you need to instnatiate a AnnotationConfiguration.

-max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 23, 2005 12:20 pm 
Beginner
Beginner

Joined: Mon Mar 21, 2005 1:39 pm
Posts: 28
Well.... , okay,...that's right, and I already changed that, and I'm getting an new Error Message:
NoSuchMethodError:
org.hibernate.mapping.PersistentClass.setDynamic(Z)V[b]
And this message is really weired, because I looked at the source code of PersistentClass, and this method really doesn't exist. Only setDynamixInsert and setDynamicUpdate exists (I'm not sure with the names).

[b]Code between sessionFactory.openSession() and session.close():

Code:
public static void main(String[] args) throws HibernateException,
         SQLException {
      //create session
      Session session = HibernateUtil.currentSession();

      //examples of using database with Contacts
      //examplesContact(session);

      //exapmles of using database with Folders
      //examplesFolder(session);

      // close Session
      HibernateUtil.closeSession();
      System.exit(0);
   }


And thats class HibernateUtil
public class HibernateUtil {

private static final SessionFactory sessionFactory;
private static final AnnotationConfiguration cfg;

static {
try {
cfg = new AnnotationConfiguration();
cfg.configure();
new SchemaUpdate(cfg).execute(true, true);
sessionFactory = cfg.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);
}
}
.
.
.
.
[/code]

Full stack trace of any exception that occurs:
Initial SessionFactory creation failed.java.lang.NoSuchMethodError:
org.hibernate.mapping.PersistentClass.setDynamic(Z)V Exception in
thread "main" java.lang.ExceptionInInitializerError
at main.HibernateUtil.<clinit>(HibernateUtil.java:36)
at main.Shell.main(Shell.java:34)
Caused by: java.lang.NoSuchMethodError:
org.hibernate.mapping.PersistentClass.setDynamic(Z)V
at org.hibernate.cfg.AnnotationBinder.bindEntity(AnnotationBinder.java:514)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:278)
at org.hibernate.cfg.AnnotationConfiguration.addAnnotatedClass(AnnotationConfiguration.java:44)
at org.hibernate.cfg.AnnotationConfiguration.parseMappingElement(AnnotationConfiguration.java:182)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1353)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1335)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1302)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1230)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1216)
at main.HibernateUtil.<clinit>(HibernateUtil.java:27)
... 1 more

Regards,
Martin



[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 23, 2005 1:14 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
seems like annotations is using a method that is now removed in H3 RC.

you'll have to use a older version of hibernate 3 to work with annotations.

you could try the cvs version of annotations if you want ,)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 24, 2005 8:19 am 
Beginner
Beginner

Joined: Mon Mar 21, 2005 1:39 pm
Posts: 28
Hallo,
Hibernate3.0beta 4 solved the problem!
Thanks for helping!
Regards,
Martin


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