-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate Annotations Mapping & Rev Engineering Problems
PostPosted: Sun Mar 02, 2008 12:33 pm 
Newbie

Joined: Sun Mar 02, 2008 11:59 am
Posts: 1
Location: Ireland
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate3 (Latest Download)

Mapping documents:
package com.rentalscontroller.gui.pojo;

import java.io.Serializable;
import javax.persistence.*;

@Entity
@Table(name="Owner", schema="RENTALS")
public class Owner implements Serializable{
static final long serialVersionUID = 99999;

private Integer ownerId;
private String firstName;
private String surname;
private String telNo;
private Integer currentStat;

public Owner(){}

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="ownerId", unique=true, nullable=false)
public Integer getOwnerId() {
return ownerId;
}

public void setOwnerId(Integer ownerId) {
this.ownerId = ownerId;
}

@Column(name="firstName", length=32)
public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

@Column(name="surname",length=32)
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
surname = surname;
}

@Column(name="telNo",length=20)
public String getTelNo() {
return telNo;
}
public void setTelNo(String telNo) {
this.telNo = telNo;
}

@Column(name="currentStat")
public Integer getCurrentStat() {
return currentStat;
}

public void setCurrentStat(Integer currentStat) {
this.currentStat = currentStat;
}
}


AnnotationConfiguration ac = new AnnotationConfiguration();
//ac.addPackage("com.rentalscontroller.gui.pojo");
ac.addAnnotatedClass(Owner.class);
SessionFactory sessionFactory = ac.configure().buildSessionFactory();

Session session = sessionFactory.openSession(); // changed to
// openSession
Transaction tx = session.beginTransaction();
Owner owner;

// Demo 1: Get single record
owner = (Owner) session.load(Owner.class, new Integer(1));
System.out.println("Name for node = " + owner.getFirstName());

// Demo 2: Get all records
List nodeList = session.createQuery("from Owner").list();
for (int i = 0; i < nodeList.size(); i++)
{
owner = (Owner) nodeList.get(i);
System.out.println("Label " + (i + 1) + "> " + owner.getFirstName());
}
tx.commit();
session.close();
sessionFactory.close();


2008-03-02 16:26:43,328 INFO [org.hibernate.cfg.annotations.Version] - Hibernate Annotations 3.3.0.GA
2008-03-02 16:26:43,359 INFO [org.hibernate.cfg.Environment] - Hibernate 3.2.6
2008-03-02 16:26:43,375 INFO [org.hibernate.cfg.Environment] - hibernate.properties not found
2008-03-02 16:26:43,390 INFO [org.hibernate.cfg.Environment] - Bytecode provider name : cglib
2008-03-02 16:26:43,406 INFO [org.hibernate.cfg.Environment] - using JDK 1.4 java.sql.Timestamp handling
2008-03-02 16:26:43,718 INFO [org.hibernate.cfg.Configuration] - configuring from resource: /hibernate.cfg.xml
2008-03-02 16:26:43,718 INFO [org.hibernate.cfg.Configuration] - Configuration resource: /hibernate.cfg.xml
2008-03-02 16:26:44,437 INFO [org.hibernate.cfg.Configuration] - Configured SessionFactory: null
2008-03-02 16:26:44,656 INFO [org.hibernate.cfg.AnnotationBinder] - Binding entity from annotated class: com.rentalscontroller.gui.pojo.Owner
2008-03-02 16:26:44,796 INFO [org.hibernate.cfg.annotations.EntityBinder] - Bind entity com.rentalscontroller.gui.pojo.Owner on table Owner
2008-03-02 16:26:44,984 INFO [org.hibernate.cfg.AnnotationConfiguration] - Hibernate Validator not found: ignoring
2008-03-02 16:26:45,531 INFO [org.hibernate.connection.DriverManagerConnectionProvider] - Using Hibernate built-in connection pool (not for production use!)
2008-03-02 16:26:45,546 INFO [org.hibernate.connection.DriverManagerConnectionProvider] - Hibernate connection pool size: 20
2008-03-02 16:26:45,546 INFO [org.hibernate.connection.DriverManagerConnectionProvider] - autocommit mode: false
2008-03-02 16:26:45,562 INFO [org.hibernate.connection.DriverManagerConnectionProvider] - using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:f:\rentalscontroller\src\data1\rentals
2008-03-02 16:26:45,562 INFO [org.hibernate.connection.DriverManagerConnectionProvider] - connection properties: {user=sa}
2008-03-02 16:26:48,484 INFO [org.hibernate.cfg.SettingsFactory] - RDBMS: HSQL Database Engine, version: 1.8.0
2008-03-02 16:26:48,484 INFO [org.hibernate.cfg.SettingsFactory] - JDBC driver: HSQL Database Engine Driver, version: 1.8.0
2008-03-02 16:26:48,546 INFO [org.hibernate.dialect.Dialect] - Using dialect: org.hibernate.dialect.HSQLDialect
2008-03-02 16:26:48,562 INFO [org.hibernate.transaction.TransactionFactoryFactory] - Using default transaction strategy (direct JDBC transactions)
2008-03-02 16:26:48,578 INFO [org.hibernate.transaction.TransactionManagerLookupFactory] - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
2008-03-02 16:26:48,578 INFO [org.hibernate.cfg.SettingsFactory] - Automatic flush during beforeCompletion(): disabled
2008-03-02 16:26:48,578 INFO [org.hibernate.cfg.SettingsFactory] - Automatic session close at end of transaction: disabled
2008-03-02 16:26:48,578 INFO [org.hibernate.cfg.SettingsFactory] - JDBC batch size: 15
2008-03-02 16:26:48,578 INFO [org.hibernate.cfg.SettingsFactory] - JDBC batch updates for versioned data: disabled
2008-03-02 16:26:48,578 INFO [org.hibernate.cfg.SettingsFactory] - Scrollable result sets: enabled
2008-03-02 16:26:48,578 INFO [org.hibernate.cfg.SettingsFactory] - JDBC3 getGeneratedKeys(): disabled
2008-03-02 16:26:48,578 INFO [org.hibernate.cfg.SettingsFactory] - Connection release mode: auto
2008-03-02 16:26:48,578 INFO [org.hibernate.cfg.SettingsFactory] - Default schema: RENTALS
2008-03-02 16:26:48,578 INFO [org.hibernate.cfg.SettingsFactory] - Default batch fetch size: 1
2008-03-02 16:26:48,578 INFO [org.hibernate.cfg.SettingsFactory] - Generate SQL with comments: disabled
2008-03-02 16:26:48,578 INFO [org.hibernate.cfg.SettingsFactory] - Order SQL updates by primary key: disabled
2008-03-02 16:26:48,578 INFO [org.hibernate.cfg.SettingsFactory] - Order SQL inserts for batching: disabled
2008-03-02 16:26:48,578 INFO [org.hibernate.cfg.SettingsFactory] - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
2008-03-02 16:26:48,593 INFO [org.hibernate.hql.ast.ASTQueryTranslatorFactory] - Using ASTQueryTranslatorFactory
2008-03-02 16:26:48,593 INFO [org.hibernate.cfg.SettingsFactory] - Query language substitutions: {}
2008-03-02 16:26:48,593 INFO [org.hibernate.cfg.SettingsFactory] - JPA-QL strict compliance: disabled
2008-03-02 16:26:48,593 INFO [org.hibernate.cfg.SettingsFactory] - Second-level cache: enabled
2008-03-02 16:26:48,593 INFO [org.hibernate.cfg.SettingsFactory] - Query cache: disabled
2008-03-02 16:26:48,593 INFO [org.hibernate.cfg.SettingsFactory] - Cache provider: org.hibernate.cache.NoCacheProvider
2008-03-02 16:26:48,593 INFO [org.hibernate.cfg.SettingsFactory] - Optimize cache for minimal puts: disabled
2008-03-02 16:26:48,593 INFO [org.hibernate.cfg.SettingsFactory] - Structured second-level cache entries: disabled
2008-03-02 16:26:48,609 INFO [org.hibernate.cfg.SettingsFactory] - Statistics: disabled
2008-03-02 16:26:48,609 INFO [org.hibernate.cfg.SettingsFactory] - Deleted entity synthetic identifier rollback: disabled
2008-03-02 16:26:48,609 INFO [org.hibernate.cfg.SettingsFactory] - Default entity-mode: pojo
2008-03-02 16:26:48,609 INFO [org.hibernate.cfg.SettingsFactory] - Named query checking : enabled
2008-03-02 16:26:48,734 INFO [org.hibernate.impl.SessionFactoryImpl] - building session factory
2008-03-02 16:26:49,468 INFO [org.hibernate.impl.SessionFactoryObjectFactory] - Not binding factory to JNDI, no JNDI name configured
2008-03-02 16:26:49,625 WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: -22, SQLState: S0002
2008-03-02 16:26:49,625 ERROR [org.hibernate.util.JDBCExceptionReporter] - Table not found in statement [select owner0_.ownerId as ownerId0_0_, owner0_.currentStat as currentS2_0_0_, owner0_.firstName as firstName0_0_, owner0_.surname as surname0_0_, owner0_.telNo as telNo0_0_ from RENTALS.Owner owner0_ where owner0_.ownerId=?]
Exception in thread "main" 2008-03-02 16:26:49,625 INFO [org.hibernate.event.def.DefaultLoadEventListener] - Error performing load command
org.hibernate.exception.SQLGrammarException: could not load an entity: [com.rentalscontroller.gui.pojo.Owner#1]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1874)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:42)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3049)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:399)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:375)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:139)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:98)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:836)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:66)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150)
at com.rentalscontroller.gui.pojo.Owner$$EnhancerByCGLIB$$2dec4ded.getFirstName(<generated>)
at com.rentalscontroller.test.HibernateTest.main(HibernateTest.java:25)
Caused by: java.sql.SQLException: Table not found in statement [select owner0_.ownerId as ownerId0_0_, owner0_.currentStat as currentS2_0_0_, owner0_.firstName as firstName0_0_, owner0_.surname as surname0_0_, owner0_.telNo as telNo0_0_ from RENTALS.Owner owner0_ where owner0_.ownerId=?]
at org.hsqldb.jdbc.Util.throwError(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:505)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:423)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1547)
at org.hibernate.loader.Loader.doQuery(Loader.java:673)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1860)
... 14 more
org.hibernate.exception.SQLGrammarException: could not load an entity: [com.rentalscontroller.gui.pojo.Owner#1]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1874)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:48)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:42)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3049)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:399)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:375)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:139)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:98)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
at org.hibernate.impl.SessionImpl.immediateLoad(SessionImpl.java:836)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:66)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150)
at com.rentalscontroller.gui.pojo.Owner$$EnhancerByCGLIB$$2dec4ded.getFirstName(<generated>)
at com.rentalscontroller.test.HibernateTest.main(HibernateTest.java:25)
Caused by: java.sql.SQLException: Table not found in statement [select owner0_.ownerId as ownerId0_0_, owner0_.currentStat as currentS2_0_0_, owner0_.firstName as firstName0_0_, owner0_.surname as surname0_0_, owner0_.telNo as telNo0_0_ from RENTALS.Owner owner0_ where owner0_.ownerId=?]
at org.hsqldb.jdbc.Util.throwError(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:505)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:423)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1547)
at org.hibernate.loader.Loader.doQuery(Loader.java:673)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1860)
... 14 more



HSQLDB 1.8.0


I have been trying for several days now to get this to work.

When I use the Hibernate tools plugin for Eclipse I get the following errors when trying to expand the database node beneath the Hibernate configuration:

2008-03-02 16:30:34,171 WARN Worker-10 org.hibernate.cfg.reveng.JDBCReader - The JDBC driver didn't report any primary key columns in Owner. Asking rev.eng. strategy
2008-03-02 16:30:34,171 WARN Worker-10 org.hibernate.cfg.reveng.JDBCReader - Rev.eng. strategy did not report any primary key columns for Owner


The database has been created using primary keys...

CREATE MEMORY TABLE "Owner"("ownerId" INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY,"firstName" CHAR(32),"surname" CHAR(32),"telNo" CHAR(20),"currentStat" INTEGER)


I can see the database tables in Eclipse but not the column details. Could it be because the database is an "in memory" database? (I really want a persistent database but haven't been able to configure HSQLDB to do this yet)

I am able to connect to the database using the Eclipse Database Development plugin and cann see all tables, columns and data.

Please Help!!

Michael


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.