I've i run into an exeption while trying to use Hibernate 4.3.x with java on netbeans, the exption is:
Exception in thread "main" java.lang.ExceptionInInitializerError
at teste.ConectaJavaDB.main(ConectaJavaDB.java:17)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from resource model/Equipe.hbm.xml
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:3764)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXmlQueue(Configuration.java:3753)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3741)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1410)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844)
at conexao.HibernateUtil.buildSessionFactory(HibernateUtil.java:25)
at conexao.HibernateUtil.<clinit>(HibernateUtil.java:14)
... 1 more
Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping model.Equipe
at org.hibernate.cfg.Configuration$MappingsImpl.addClass(Configuration.java:2837)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:178)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:3761)
... 7 more
(the second error says about duplicate mapping, but i dindt mapped twice)
by reading the exeption, it's possible to see that the problem is in the mapping xml of the class Equipe, the XML contains:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="model">
<class name="model.Equipe" table="equipe">
<id name="id" type="int" column="ID" >
<generator class="increment"/>
</id>
<property name="nome"/>
<property name="dataNascimento"/>
<property name="email"/>
<property name="enderecoWeb"/>
<property name="fone"/>
</class>
</hibernate-mapping>
And the class:
package model;
import java.util.Date;
public class Equipe {
private int id;
private String nome;
private Date dataNascimento;
private String email;
private String enderecoWeb;
private String fone;
[..]getters and setters[..]
Hibernate.cgf
<?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.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:3306/mysql?zeroDateTimeBehavior=convertToNull</property>
<property name="hibernate.connection.username">app</property>
<property name="hibernate.connection.password">app</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping class="model.Jogador"/>
<mapping resource="model/Equipe.hbm.xml"/>
</session-factory>
</hibernate-configuration>
I can't seem to find the error, the hole code is posted on Bitbucket above, thanks!
Hole code: https://bitbucket.org/angelorodem/progapl_ii_272278_2015/src
You invoked configuration.configure() twice. Remove the second invocation, or just copy paste the code below:
Configuration configuration = new Configuration();
configuration.configure();
serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
return sessionFactory;
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping class="model.Jogador"/> (remove this)
<mapping resource="model/Equipe.hbm.xml"/>
try this:
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping resource="model/Equipe.hbm.xml"/>
Related
I'm currently trying to learn to use Hibernate to store objects in a database. I've been working through a tutorial at https://netbeans.org/kb/docs/java/hibernate-java-se.html and I'm trying to create an XML file for a very simple class and table. However I'm just totally unable to get it to work and I'm now really getting frustrated. I just can't get it to work.
The database is Postgres 9.2, the class is one I wrote myself and the version of Hibernate is the one that ships with Netbeans 7.3 (3.2, I believe).
The table is as follows:
CREATE TABLE sellable.manufacturers
(
mfr_id serial NOT NULL, -- Manufacturer ID
mfr_name character varying(127) NOT NULL, -- Manufacturer name
CONSTRAINT manufacturers_pkey PRIMARY KEY (mfr_id),
CONSTRAINT manufacturers_mfr_name_key UNIQUE (mfr_name)
);
The class I'm trying to map it to is as follows:
package bikeshop.sellable;
import java.io.Serializable;
public class Manufacturer implements Serializable {
private Integer mfrId = null;
private String mfrName = null;
public Integer getMfrId () {
return this.mfrId;
}
public String getMfrName () {
return this.mfrName;
}
public void setMfrName (String MfrName) {
this.mfrName = MfrName;
}
}
The XML for the Hibernate mapping is:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Aug 21, 2013 7:20:20 PM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="bikeshop.sellable.Manufacturer" table="manufacturers" schema="sellable">
<comment>Product manufacturers</comment>
<id name="mfrId" type="int">
<column name="mfr_id" />
<generator class="assigned" />
</id>
<property name="mfrName" type="string">
<column name="mfr_name" length="127" not-null="true" unique="true">
<comment>Manufacturer name</comment>
</column>
</property>
</class>
</hibernate-mapping>
And the Hibernate project config is:
<?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.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost/bikeshop</property>
<property name="hibernate.connection.username">bikeshop</property>
<property name="hibernate.connection.password">bikeshop</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
<property name="hibernate.format_sql">true</property>
<mapping class="bikeshop.sellable.Manufacturer" file="" jar="" package="" resource="bikeshop/mappings/Manufacturers.hbm.xml"/>
<mapping resource="bikeshop/mappings/Sellables.hbm.xml"/>
</session-factory>
</hibernate-configuration>
When I try using the HQL query editor, all I get is the query "select from" displayed, which obviously can't be executed. Attempting to execute it results in an exception.
org.hibernate.exception.SQLGrammarException: could not execute query
Why is this failing to generate a valid SQL query? What am I missing?
EDIT: I've been trying to get this to work, now I'm getting a different error. The HQL query window now displays the message "Unable to retrieve data from the database." and the exception has changed to "org.hibernate.PropertyNotFoundException: Could not find a setter for property mfrId in class bikeshop.sellable.Manufacturer"
The config file has changed to:
<?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.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">jdbc:postgresql://localhost/bikeshop</property>
<property name="hibernate.connection.username">bikeshop</property>
<property name="hibernate.connection.password">bikeshop</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
<property name="hibernate.format_sql">true</property>
<mapping class="bikeshop.sellable.Manufacturer" file="" jar="" package="bikeshop.sellable" resource="bikeshop/mappings/manufacturer.hbm.xml"/>
</session-factory>
</hibernate-configuration>
and the mapping file has changed to:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="bikeshop.sellable.Manufacturer" table="manufacturers" schema="sellable">
<comment>Product manufacturers</comment>
<id name="mfrId" type="int">
<column name="mfr_id" />
<generator class="native" />
</id>
<property name="mfrName" type="string">
<column name="mfr_name" length="127" not-null="true" unique="true">
<comment>Manufacturer name</comment>
</column>
</property>
</class>
</hibernate-mapping>
EDIT 2: As a last ditch attempt I made all the Manufacturer members public and changed the access type to field in the XML.
Now the HQL query works and returns results. But I obviously don't want to take that approach, public fields are a horrible idea!
It seems that the problem is that the HQL editor doesn't get updated classes or metadata all the time when you make changes to the class or its metadata, it also seems that this can happen regardless of whether you use an external XML file or inline annotations.
The only workaround I've found so far is to quit Netbeans and restart it. This makes the HQL query editor update, but is obviously quite annoying.
I'm trying to store an object Ficheiro inside my in-memory database. This object contains:
private int version;
private Workbook content;
This is my code I'm using to store in the database:
HSQLServerUtil.getInstance().start("DBMemoria");
Ficheiro fich = new Ficheiro();
fich.setVersion(1);
fich.setContent(workbook);
byte[] by = serialize(fich);
try {
Blob blob = new SerialBlob(by);
Session ss = HibernateUtils.newSessionFactory("csheets\\ext\\Hibernate\\hibernate.cfg.xml").openSession();
ss.beginTransaction();
ss.getTransaction();
ss.save(workbook);
ss.getTransaction().commit();
ss.close();
} catch (SQLException ex) {
System.out.println("ERROR");
}
This is my hibernate.cfg.xml file:
<?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.hbm2ddl.auto">create</property>
<property name="hibernate.connection.url">jdbc:hsqldb:file:C:\Users\Adam\Documents\NetBeansProjects\lapr4_2dd_g1_s2\lib\Version</property>
<property name="hibernate.connection.username"/>
<property name="hibernate.connection.password"/>
<mapping resource="csheets/ext/Hibernate/File.hbm.xml"/>
</session-factory>
</hibernate-configuration>
And finally this is my File.hbm.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class dynamic-insert="false" dynamic-update="false" mutable="true" name="csheets.ext.Hibernate.Ficheiro" optimistic-lock="version" polymorphism="implicit" select-before-update="false" table="File">
<id column="version" name="version" type="int" unsaved-value="0">
<generator class="identity">
</generator>
</id>
<property column="content" name="content" type="blob"/>
<!--<property column="name" name="name" type="string"/>-->
</class>
</hibernate-mapping>
I'm getting the following error:
Exception in thread "AWT-EventQueue-0" org.hibernate.MappingException: Unknown entity: csheets.core.Workbook
I've already put an #Entity in the Workbook class. Anybody know whats wrong?
And if possible, can you tell me if i'm doing this right?
Thanks
Update your hibernate config to the following to make it work (for development machine):
<property name="hibernate.hbm2ddl.auto">update</property>
When I run the project, it occurs an exception as below. Before I add a view table in Hibernate, everyting got well include the Blame.hbm.xml and others. And it could read the data from database. The exception occurs in ShowOrderDaoImpl.java at this sentence: session=HibernateSessionFactory.getSession();
My exception
org.hibernate.InvalidMappingException: Could not parse mapping document from resource pojo/Blame.hbm.xml
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:3415)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXmlQueue(Configuration.java:3404)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3392)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1341)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1737)
at session.factory.HibernateSessionFactory.rebuildSessionFactory(HibernateSessionFactory.java:75)
at session.factory.HibernateSessionFactory.getSession(HibernateSessionFactory.java:57)
at dao.impl.ShowOrderDaoImpl.queryTradesByBid(ShowOrderDaoImpl.java:24)
at test.testHibernate.main(testHibernate.java:45)
Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping pojo.Blame
ok
at org.hibernate.cfg.Configuration$MappingsImpl.addClass(Configuration.java:2580)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:174)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:3412)
... 8 more
java.lang.NullPointerException
at dao.impl.ShowOrderDaoImpl.queryTradesByBid(ShowOrderDaoImpl.java:25)
at test.testHibernate.main(testHibernate.java:45)
my hibernate.cfg.xml file
<?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">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/disputesystem</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.show_sql">true</property>
<mapping resource="pojo/Blame.hbm.xml"/>
<mapping resource="pojo/Buyer.hbm.xml"/>
<mapping resource="pojo/Dispute.hbm.xml"/>
<mapping resource="pojo/Evidence.hbm.xml"/>
<mapping resource="pojo/Goods.hbm.xml"/>
<mapping resource="pojo/Message.hbm.xml"/>
<mapping resource="pojo/Record.hbm.xml"/>
<mapping resource="pojo/Seller.hbm.xml"/>
<mapping resource="pojo/Staff.hbm.xml"/>
<mapping resource="pojo/Trade.hbm.xml"/>
<mapping resource="pojo/Fund.hbm.xml"/>
<mapping resource="pojo/Showorderbybid.hbm.xml"/>
</session-factory>
</hibernate-configuration>
my ShowOrderDaoImpl.java file
package dao.impl;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import pojo.Showorderbybid;
import session.factory.HibernateSessionFactory;
import dao.intf.ShowOrderDao;
public class ShowOrderDaoImpl implements ShowOrderDao{
#Override
public List<Showorderbybid> queryTradesByBid(String bid) throws Exception {
Session session=null;
Transaction transaction=null;
List<Showorderbybid> orders=new ArrayList<Showorderbybid>();
try {
session=HibernateSessionFactory.getSession();
transaction=session.beginTransaction();
Query query=session.createQuery("from Showorderbybid where bid=?");
query.setParameter(0, bid);
orders=(List<Showorderbybid>)query.list();
List CountView = new ArrayList();
Iterator it = orders.iterator();
while (it.hasNext()) {
Object[] all = (Object[]) it.next();
Showorderbybid countViewId = new Showorderbybid();
countViewId.setAmount((Integer) all[0]);
countViewId.setBid((String) all[1]);
countViewId.setDetail((String) all[2]);
countViewId.setGid((String)all[3]);
countViewId.setGname((String)all[4]);
countViewId.setLogistics((String)all[5]);
countViewId.setSid((String)all[6]);
countViewId.setSname((String)all[7]);
countViewId.setStatus((String)all[8]);
countViewId.setTid((String)all[9]);
countViewId.setTotalmoney((Integer) all[10]);
countViewId.setTradetime((Date)all[11]);
orders.add(countViewId);
}
} catch (Exception e) {
e.printStackTrace();
}finally{
HibernateSessionFactory.closeSession();
}
return orders;
}
}
my Blame.hbm.xml file
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2013-4-19 23:02:05 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="pojo.Blame" table="blame" catalog="disputesystem">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="identity" />
</id>
<many-to-one name="dispute" class="pojo.Dispute" fetch="select">
<column name="disputeid" length="20" not-null="true" />
</many-to-one>
<property name="blametime" type="timestamp">
<column name="blametime" length="19" not-null="true" />
</property>
<property name="content" type="string">
<column name="content" length="1000" />
</property>
</class>
</hibernate-mapping>
Looks like there is another mapping for pojo.Blame. You might had a copy/paste mistake:
<class name="pojo.Blame"
In another hbm file.
This
Caused by: org.hibernate.DuplicateMappingException: Duplicate class/entity mapping pojo.Blame
States that when reached a hbm file it already has a definition for a class named pojo.Blame.
Looks like in some of this files:
<mapping resource="pojo/Blame.hbm.xml"/>
<mapping resource="pojo/Buyer.hbm.xml"/>
<mapping resource="pojo/Dispute.hbm.xml"/>
<mapping resource="pojo/Evidence.hbm.xml"/>
<mapping resource="pojo/Goods.hbm.xml"/>
<mapping resource="pojo/Message.hbm.xml"/>
<mapping resource="pojo/Record.hbm.xml"/>
<mapping resource="pojo/Seller.hbm.xml"/>
<mapping resource="pojo/Staff.hbm.xml"/>
<mapping resource="pojo/Trade.hbm.xml"/>
<mapping resource="pojo/Fund.hbm.xml"/>
<mapping resource="pojo/Showorderbybid.hbm.xml"/>
Is a misplaced <class name="pojo.Blame"
be sure that you have overrided the equals/tostring and hash methodes in your Pojo
check why the session=HibernateSessionFactory.getSession(); is getting null. That is the reason for the null pointer
Im working in a maven project. Atm I only have entities , mappings and a configuration files. Im trying to test my hibernate mappings with junit.
I cant find the problem. I can validate the xml files in netbeans, but when i run my test I get the following error.
Validation in netbeans:
XML validation started.
Checking file:/C:/Users/Err/Documents/NetBeansProjects/PinkSocks/src/main/resources/hibernate.cfg.xml...
Referenced entity at "http://localhost:8080/files/hibernate-configuration-4.0.xsd".
XML validation finished.
Error:
Initial SessionFactory creation failed.org.hibernate.MappingException: invalid configuration
at bleh.mihihi.utils.HibernateUtil.buildSessionFactory(HibernateUtil.java:25)
at bleh.mihihi.utils.HibernateUtil.<clinit>(HibernateUtil.java:16)
at bleh.mihihi.utils.HibernateUtilTest.setUp(HibernateUtilTest.java:20)
Caused by: org.hibernate.MappingException: invalid configuration
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2014)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1931)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1910)
at bleh.mihihi.utils.HibernateUtil.buildSessionFactory(HibernateUtil.java:21)
Caused by: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 25; Document is invalid: no grammar found.
at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<hibernate-configuration
xmlns="http://www.hibernate.org/xsd/hibernate-configuration"
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-configuration http://localhost:8080/files/hibernate-configuration-4.0.xsd">
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/pinksocks</property>
<property name="connection.username">root</property>
<property name="connection.password">admin</property>
<property name="connection.pool_size">1</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>
<property name="show_sql">true</property>
<mapping class="bleh.mihihi.Beverage" file="Beverage.hbm.xml" />
</session-factory>
</hibernate-configuration>
Beverage.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<hibernate-mapping
xmlns="http://www.hibernate.org/xsd/hibernate-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-mapping http://localhost:8080/files/hibernate-mapping-4.0.xsd"
package="bleh.mihihi.entities">
<class name="Beverage" table="beverages">
<id name="id" column="id">
<generator class="native"/>
</id>
<property name="name" column="name" />
<property name="alcohol" column="alcohol"/>
</class>
</hibernate-mapping>
Thanks in advance
Err
Edit1:
Things I tried:
retyping
using dtd
placing xsd to other places
With Hibernate 4.x you should use the same DTD as 3.x:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
as you can see by this bug report, where the deprecation warning was removed.
Also the tutorials for 4.2 version use this, as you can see here.
You forgot to specify DTD.
Try keeping below code in both the xml files and let me know
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
your forgot DTD in hibernate.cfg.xml file
I'm trying to use the Hibernate Code Generation feature in Hibernate Tools Eclipse Add-On. It is giving me the following error:
org.hibernate.InvalidMappingException: Could not parse mapping document from resource Alert.hbm.xml
Could not parse mapping document from resource Alert.hbm.xml
org.hibernate.MappingException: class Alert not found while looking for property: alertId
class Alert not found while looking for property: alertId
org.hibernate.MappingException: class Alert not found while looking for property: alertId
class Alert not found while looking for property: alertId
java.lang.ClassNotFoundException: Alert
Alert
It is not finding the class Alert.java but I thought the Code Generator (hence the name...) was supposed to generate all the hibernate classes for me.
Using eclipse Indigo with Hibernate Tools 3.4.x.
Here's my hibernate.cfg.xml:
<!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">
com.mysql.jdbc.Driver
</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/findata?tcpKeepAlive=true
</property>
<property name="connection.username">root</property>
<property name="connection.password">madmax1.</property>
<property name="connection.pool_size">2</property>
<property name="show_sql">true</property>
<property name="dialect">
org.hibernate.dialect.mysqldialect
</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">
org.hibernate.cache.NoCacheProvider
</property>
<mapping resource="Alert.hbm.xml" />
<mapping resource="Entity.hbm.xml" />
<mapping resource="FactData.hbm.xml" />
<mapping resource="TimeEvent.hbm.xml" />
<mapping resource="User.hbm.xml" />
<mapping resource="AlertTarget.hbm.xml" />
<mapping resource="LogAlert.hbm.xml" />
</session-factory>
</hibernate-configuration>
Here's Alert.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="Alert" table="alerts">
<id name="alertId" column="id">
<generator class="assigned"/>
</id>
<property name="limitValue" column="limit_value" type="decimal" />
<!-- The unique=true property makes the many-to-one a one-to-one relationship -->
<many-to-one name="alertEntity"
class="Entity" column="entity_id"
not-null="true" cascade="all" unique="true"/>
<set name="alert_targets" table="alerts_alert_targets" cascade="all">
<key column="alert_id" />
<many-to-many column="alert_target_id"
class="AlertTarget" />
</set>
</class>
</hibernate-mapping>
weird it is looking for the to-be-generated class.
I will check the hibernate-reverse.xml file and check if it does not have additional attributes that may result in this.
Alternatively, during generation, try to setup the hibernate-revenge.xml and hibernate.cfg.xml rather than using the existing ones.
The cause turned out to be the fact that the "type" was not specified for the "id" property in Alert.hbm.xml.