-->
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: Vererbung, Annotations -> Unknown entity
PostPosted: Sat Jul 07, 2007 5:48 am 
Newbie

Joined: Fri Jul 06, 2007 9:07 am
Posts: 5
Hibernate version:
3.2
Mapping documents:
Over Annotations
Full stack trace of any exception that occurs:
Caused by: org.hibernate.MappingException: Unknown entity: de.floe.timernx.plugin.AutoCal.AutoCalPlugin
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:550)
Name and version of the database you are using:
MySQL 5.0


Hello,

I have a program that is extendable over plugins. The plugins take playe in a folder as JAR files and where loaded over the ServioceLoader mechanism from Java 6. Every plugin has his own package an contained a specific class (AustoCalPLugin) an inherit from a generell class (Plugin)

The PluginHandler schould save the inheritet Plugin object in the DB

PluginHandler.java:
Code:
public void add() {
      ServiceLoader<Plugin> service = load();
      
      while(service.iterator().hasNext()) {
         Session session = HibernateUtil.getSessionFactory().getCurrentSession();
           session.beginTransaction();
         Plugin plugin = service.iterator().next();
           session.save(plugin);
           session.getTransaction().commit();
       }
   }


The Plugin object is an abstract class (Getter/Setter methods are cut for better viewing)

Plugin.java:
Code:
@Entity
@Table(name="plugin")
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Plugin implements Serializable{

   @Id   
   private int id;
   
   @Column(nullable=false)
   protected String name;

   @Column(nullable=false)
   protected double version;

   @Column(nullable=false)
   protected char status;
   
   @Column
   protected String[] dependencies;
   protected abstract void actions();
   protected abstract void menuBuild();
   protected abstract void init();


AutoCalPlugin.java:
Code:
@Entity
@Table(name="pluginAutoCal")
public class AutoCalPlugin extends Plugin {

   @Column(nullable=false)
   String fileName = "AutoCal.jar";
   
   public AutoCalPlugin() {
      name = "AutoCal";
      version = 1.0;
      status = 'd';
   }
   
   @Override
   public void init() {}
   @Override
   public void actions() {}
   @Override
   public void menuBuild() {}   


If I start the program Hibernate said that the don't know the entity
(Unknown entity: de.floe.timernx.plugin.AutoCal.AutoCalPlugin) but in the listet class the Entity annotation is there.

What is wrong?

Here the hibernate.cfg.xml:
Code:
<hibernate-configuration>
<session-factory>
      <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
      <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
      <property name="hibernate.connection.url">jdbc:mysql://localhost/timernx</property>
      <property name="hibernate.connection.username">xxxx</property>
      <property name="hibernate.connection.password">xxxx</property>
      <property name="hibernate.connection.pool_size">10</property>
      <property name="hibernate.hbm2ddl.auto">update</property>
      <property name="current_session_context_class">thread</property>
</session-factory>
</hibernate-configuration>


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 07, 2007 8:09 am 
Expert
Expert

Joined: Thu Jul 05, 2007 9:38 am
Posts: 287
your hibernate.cfg.xml should have entries like
<mapping class="your.class.goes.here"/>

HTH
Jens


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 07, 2007 11:46 am 
Newbie

Joined: Fri Jul 06, 2007 9:07 am
Posts: 5
That solved my problem thanks a lot. But one more question can I say that all
Plugins have a mappng file, because if I must write every class from a Plugin in the hibernate.cfg.xml the plugin system is useless.

That is the solution for now:
Every single Plugin
<mapping class="de.floe.timernx.plugin.AutoCal.AutoCalPlugin"/>
<mapping class="de.floe.timernx.plugin.ManuCal.ManuCalPlugin"/>

and I want something like this:
All Plugins together:
<mapping package="de.floe.timernx.plugin.*"/>

Is there a solution for my second problem?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 07, 2007 2:45 pm 
Expert
Expert

Joined: Thu Jul 05, 2007 9:38 am
Posts: 287
Very good question. I am actually going to have the same problem.

I haven't checked if it really works, but these are the things I'm going to check:

1. you can configure a least some settings from within your java code.
2. One could construct the hibernate.cfg.xml on the fly before starting up hibernate.


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.