-->
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.  [ 8 posts ] 
Author Message
 Post subject: Trying to create JPA based console config->ClassNotFoundE
PostPosted: Tue Apr 17, 2007 10:27 am 
Newbie

Joined: Wed Sep 20, 2006 4:06 am
Posts: 4
Hi,

I'm using Hibernate Tools 3.2.0 Beta9a and I try to get a JPA based console configuration (checking the JPA (jdk 1.5+) radio button in "Create Hibernate Console Configuration"). It's working when supplying a hibernate.cfg.xml (and using the "Core" setting), but won't when using the persistence.xml.

My persistence.xml:

Code:
<?xml version="1.0" encoding="UTF-8" ?>
   <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
   <persistence-unit name="KundenbeispielJPA">
      <properties>
         <property name="hibernate.show_sql" value="true"/>
         <property name="hibernate.hbm2ddl.auto" value="create"/>
         <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/>
         <property name="hibernate.connection.url" value="jdbc:hsqldb:hsql://localhost:1701/"/>
         <property name="hibernate.connection.username" value="sa"/>
         <property name="hibernate.connection.password" value=""/>
      </properties>
   </persistence-unit>
</persistence>


My hibernate.cfg.xml:

Code:
<?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>
        <property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
        <property name="hibernate.connection.url">jdbc:hsqldb:hsql://127.0.0.1:1701</property>
        <property name="hibernate.connection.username">sa</property>
        <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
        <property name="hibernate.session_factory_name">java:hibernate/SessionFactory</property>
    </session-factory>
</hibernate-configuration>


The Exception I get:
Code:
org.hibernate.console.HibernateConsoleRuntimeException: Could not load JPA Configuration
  org.hibernate.console.HibernateConsoleRuntimeException: Could not create JPA based Configuration
    org.hibernate.console.HibernateConsoleRuntimeException: Could not create JPA based Configuration
    java.lang.reflect.InvocationTargetException: <no message>
    javax.persistence.PersistenceException: [PersistenceUnit: KundenbeispielJPA] class or package not found
    java.lang.ClassNotFoundException: [color=red]bin.[/color]de.xyz.model.Kunden


My java File:

Code:
package de.xyz.model;

// Generated 17.04.2007 14:21:10 by Hibernate Tools 3.2.0.b9

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

/**
* Kunden generated by hbm2java
*/
@Entity
@Table(name = "KUNDEN", schema = "PUBLIC")
public class Kunden implements java.io.Serializable {

   private static final long serialVersionUID = 3887336267590432399L;

   private Long id;

   private String vorname;

   private String nachname;

   public Kunden() {
   }

   public Kunden(Long id) {
      this.id = id;
   }

   public Kunden(Long id, String vorname, String nachname) {
      this.id = id;
      this.vorname = vorname;
      this.nachname = nachname;
   }

   @Id
   @Column(name = "ID", precision = 646456993, scale = 0)
   public Long getId() {
      return this.id;
   }

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

   @Column(name = "VORNAME", length = 50)
   public String getVorname() {
      return this.vorname;
   }

   public void setVorname(String vorname) {
      this.vorname = vorname;
   }

   @Column(name = "NACHNAME", length = 50)
   public String getNachname() {
      return this.nachname;
   }

   public void setNachname(String nachname) {
      this.nachname = nachname;
   }

}


I understand the exception since there is no "bin.de.xyz.model.Kunden", but there is a "de.xyz.model.Kunden". I don't understand how the bin. is getting there.

Probably I did some smaller error but I'm searching for hours now and just don't get it working.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 17, 2007 10:35 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
do you by any chance have your root of your project on the classpath ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 17, 2007 11:28 am 
Newbie

Joined: Wed Sep 20, 2006 4:06 am
Posts: 4
Thanks! That solved the problem. I added the porject root to the CLASSPATH tab. On the other hand that was the only way to get the thing working at all.

I have this structure:

Root
\- src
\- META-INF
\- ...

META-INF belongs to the classpath, but the console doesn't find the persistence.xml there. It has to be in "META-INF\" relative to the classpath. So I changed it to:

Root
\- src
\- etc
... \-META-INF

and added "etc" to the classpath.

Or am I wrong? Seems strange to me, since I use that kind of folder structure a lot.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 18, 2007 2:47 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
sure - but putting root on the classpath to make META-INF visible also makes everything else in root visibile...meaning the automatic scanning will bump into alot of other things - including you bin/*.class'es

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 18, 2007 7:10 am 
Newbie

Joined: Wed Sep 20, 2006 4:06 am
Posts: 4
I agree that it wasn't to clever to put the root on the classpath :-)

I'm just not sure if it is convenient, that the persistence.xml isn't found even when the META-INF dir is on the classpath. That forces the user to use a special directory structure if he wants to use the console with JPA features (META-INF must be in a subfolder).

But probably not a very common problem.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 18, 2007 7:13 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
If you can come up with another way of putting META-INF/persistence.xml on the classpath without putting it on the classpath then feel free ;)

But yes, this is one of the downsides by the JPA spec - that the classpath is used to locate/load the config.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 03, 2007 12:59 pm 
Newbie

Joined: Tue Nov 25, 2003 11:49 pm
Posts: 12
I have a similar problem insofar as I'm trying to setup CaveatEmptor-JPA in the Hibernate Console.

Presumably there is not properties file and if I have the conf directory on my classpath ie. META-INF underneath that isn't it suppose to find persistence.xml?

Why when I click on Session Factory and Database can it not connect?

Oh I'm probably expected to have jboss running when I do this right?

max wrote:
If you can come up with another way of putting META-INF/persistence.xml on the classpath without putting it on the classpath then feel free ;)

But yes, this is one of the downsides by the JPA spec - that the classpath is used to locate/load the config.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 12, 2007 8:22 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
No - jboss as have nothing to do with running JPA.

The rest of your question I don't really understand ;)

the *only* location requirement there is for running with JPA isthat you have a entry in classpath so the following file exist:

<entry-in-classpath>/META-INF/persistence.xml

_________________
Max
Don't forget to rate


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