-->
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.  [ 12 posts ] 
Author Message
 Post subject: Unable to get started..
PostPosted: Sat Mar 24, 2012 8:35 pm 
Newbie

Joined: Sat Mar 24, 2012 8:29 pm
Posts: 8
Hi, I have been trying to write a simple persistance of some data using Hibernate, but I have gotten stuck on this exception:

org.hibernate.MappingNotFoundException: resource: <some path>/<Something>.hbm.xml not found
at org.hibernate.cfg.Configuration.addResource(Configuration.java:701)
at org.hibernate.cfg.Configuration.addClass(Configuration.java:746)
at <Something>.<init>(<Something>.java:37)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at org.picocontainer.injectors.AbstractInjector.newInstance(AbstractInjector.java:147)
at org.picocontainer.injectors.ConstructorInjector$1.run(ConstructorInjector.java:348)

I've cut the stacktrace a bit short in addition to censoring some parts.

Why does it look for xml files? I don't want xml files. I am using annotations..

This is the top part of my entity class:

@DynamicUpdate
@Table(appliesTo = "uniqueInventories")
public class InventoryStorage {

@Id
@Column(name = "playerName")
public String getPlayerName()

Please help, I am unsure how to proceed..

// Regards, doc


Top
 Profile  
 
 Post subject: Re: Unable to get started..
PostPosted: Mon Mar 26, 2012 5:46 am 
Senior
Senior

Joined: Tue Oct 28, 2008 10:39 am
Posts: 196
org.hibernate.MappingNotFoundException: resource: <some path>/<Something>.hbm.xml not found

If you use annotations there should be a xml-File for that entity. Please show the relevant part of hibernate.cfg.xml.


Top
 Profile  
 
 Post subject: Re: Unable to get started..
PostPosted: Mon Mar 26, 2012 6:24 am 
Newbie

Joined: Sat Mar 24, 2012 8:29 pm
Posts: 8
I do not have any xml files, nor do I want them..
Are you saying xml isn't optional? :(


Top
 Profile  
 
 Post subject: Re: Unable to get started..
PostPosted: Mon Mar 26, 2012 6:36 am 
Senior
Senior

Joined: Tue Oct 28, 2008 10:39 am
Posts: 196
Ups, sorry... "there should not be".

You have to "declare" either the hbm.xml or the class inside your hibernate.cfg.xml.


Top
 Profile  
 
 Post subject: Re: Unable to get started..
PostPosted: Mon Mar 26, 2012 6:45 am 
Newbie

Joined: Sat Mar 24, 2012 8:29 pm
Posts: 8
I do not have a hibernate.cfg.xml and if I have to have such a file, then I'm sorry to say that hibernate is not compatible with my design goals..
I've written configuration in code, following a guide I found on the web, but that isn't actually possible, then?

I'll return to this thread later tonight when I'm back home and I'll then post some of my code as it relates to hibernate.

As I am entirely new to the Java scene, I know not what frameworks exists nor what their induvidual strengths are..
Any suggestions of what alternatives I should look into?

// Regards, doc


Top
 Profile  
 
 Post subject: Re: Unable to get started..
PostPosted: Mon Mar 26, 2012 6:52 am 
Senior
Senior

Joined: Tue Oct 28, 2008 10:39 am
Posts: 196
I don't know PicoContainer, so I don't know how to configure it to use Hibernate. But somehow PicoContainer has to know about <Something> to be an entity-type and thinks to need a hbm.xml-File.

Could you post a link to the tutorial you used?


Top
 Profile  
 
 Post subject: Re: Unable to get started..
PostPosted: Mon Mar 26, 2012 6:56 am 
Newbie

Joined: Sat Mar 24, 2012 8:29 pm
Posts: 8
Will do, this evening :)


Top
 Profile  
 
 Post subject: Re: Unable to get started..
PostPosted: Mon Mar 26, 2012 10:15 am 
Newbie

Joined: Sat Mar 24, 2012 8:29 pm
Posts: 8
Okay, back home now..

The guide I used: http://www.java-entrepreneur.com/502267 ... no_xml.php
When I click the image or the link below it, I get an empty popup, so if there is some more things needed that have been cut off, that might explain my problem, I guess?

The code I have to set up hibernate:
Code:
      Properties props = new Properties();
      props.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
      props.put("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
      props.put("hibernate.connection.url", config.getConfigValueAsString("database.url"));
      props.put("hibernate.connection.username", config.getConfigValueAsString("database.username"));
      props.put("hibernate.connection.password", config.getConfigValueAsString("database.password"));
      props.put("hibernate.connection.pool_size", "1");
      props.put("hibernate.hbm2ddl.auto", "create");
      
      props.put("hibernate.show_sql", "false");
      props.put("hibernate.jdbc.use_streams_for_binary", "true");
      props.put("hibernate.use_outer_join", "false");
      props.put("hibernate.jdbc.batch_size", "0");
      props.put("hibernate.jdbc.use_scrollable_resultset", "true");
      props.put("hibernate.statement_cache.size", "0");
      
      hibernateConfig = new Configuration().setProperties(props);
      for (Class modelType : typeProvider.getModelClasses())
      {
         hibernateConfig.addClass(modelType);
      }
      ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(hibernateConfig.getProperties()).buildServiceRegistry();
      sessionFactory = hibernateConfig.buildSessionFactory(serviceRegistry);


The specific implementation of getModelClasses that gets called in that loop is this:
Code:
   @SuppressWarnings("rawtypes")
   @Override
   public Class[] getModelClasses()
   {
      return new Class[] { InventoryStorage.class };
   }


Top
 Profile  
 
 Post subject: Re: Unable to get started..
PostPosted: Mon Mar 26, 2012 5:12 pm 
Newbie

Joined: Sat Mar 24, 2012 8:29 pm
Posts: 8
My source code is now on github, you may see the whole thing here:

https://github.com/mortenn/Runsafe-Mine ... ndler.java

My entity class:
https://github.com/mortenn/UniqueInvent ... orage.java
My composite key:
https://github.com/mortenn/UniqueInvent ... ryKey.java
Registration of the entity type:
https://github.com/mortenn/UniqueInvent ... s.java#L44

// doc


Top
 Profile  
 
 Post subject: Re: Unable to get started..
PostPosted: Tue Mar 27, 2012 3:10 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Have you tried replacing hibernateConfig.addClass(modelType) with hibernateConfig.addAnnotatedClass(modelType)

I think the addClass method only look for an xml file and the addAnnotatedClass look for annotations.


Top
 Profile  
 
 Post subject: Re: Unable to get started..
PostPosted: Tue Mar 27, 2012 2:09 pm 
Newbie

Joined: Sat Mar 24, 2012 8:29 pm
Posts: 8
Spot on!

Though I get a new error now :/

java.lang.SecurityException: sealing violation: package javax.persistence is sealed
at java.net.URLClassLoader.getAndVerifyPackage(URLClassLoader.java:388)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:417)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:41)
at org.bukkit.plugin.java.JavaPluginLoader.getClassByName(JavaPluginLoader.java:234)
at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:37)
at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:29)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at org.hibernate.cfg.AnnotationBinder.determineCacheSettings(AnnotationBinder.java:960)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:578)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3431)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3385)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1337)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1727)
at no.runsafe.framework.RunsafeDatabaseHandler.<init>(RunsafeDatabaseHandler.java:40)

I just have no idea what to do about this one..

// doc


Top
 Profile  
 
 Post subject: Re: Unable to get started..
PostPosted: Tue Mar 27, 2012 2:28 pm 
Newbie

Joined: Sat Mar 24, 2012 8:29 pm
Posts: 8
If I remove the jpa jar from my manifest again, I get this exception instead:

java.lang.NoClassDefFoundError: javax/persistence/Cacheable
at org.hibernate.cfg.AnnotationBinder.determineCacheSettings(AnnotationBinder.java:960)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:578)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3431)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3385)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1337)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1727)
at no.runsafe.framework.RunsafeDatabaseHandler.<init>(RunsafeDatabaseHandler.java:40)

I am starting to think hibernate is not going to work out for my environment :/


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