Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
3.1.3
Mapping documents:
@Entity
@Table(name = "t_user", uniqueConstraints = { @UniqueConstraint(columnNames = {"id"}) })
@SequenceGenerator(name = "seq_user", sequenceName = "seq_user")
public class User implements Serializable {
private static final long serialVersionUID = 8008607787929383158L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "seq_user")
@Column( unique = true, insertable = false, updatable = false, precision = 8, scale = 0 )
private Long id;
@Column( nullable = false, length = 256, unique = false, insertable = true, updatable = true, precision = 10, scale = 0 )
private String fullName;
@Column( nullable = false, length = 6, unique = true, insertable = true, updatable = true, precision = 10, scale = 0 )
private String login;
@Column( nullable = false, length = 6, unique = false, insertable = true, updatable = true, precision = 10, scale = 0 )
private String password;
@ManyToOne
@JoinColumn(name="id_profile")
private Profile profile;
// Constructor, getters and setters
}
@Entity
@Table(name = "t_profile", uniqueConstraints = { @UniqueConstraint(columnNames = {"id_profile"}) })
@SequenceGenerator(name = "seq_profile", sequenceName = "seq_profile")
public class Profile implements Serializable {
private static final long serialVersionUID = -1544895999197247370L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "seq_profile")
@Column( name = "id_profile", unique = true, insertable = false, updatable = false, precision = 8, scale = 0 )
private Long id;
@Column( name = "description", nullable = false, unique = true, insertable = true, updatable = true, precision = 10, scale = 0 )
private String description;
@OneToMany(mappedBy="profile")
private Set<User> users;
// Constructor, getters and setters
}
Code between sessionFactory.openSession() and session.close():
I'm using the Hibernate suport of Spring Framework:
@Transactional(propagation = Propagation.REQUIRED, timeout = 20)
public abstract class GenericDaoImpl<T> implements GenericDao<T>,
PropertySelector {
private static Logger logger = Logger.getLogger(GenericDaoImpl.class);
protected SessionFactory sessionFactory;
protected HibernateTemplate hibernateTemplate;
private Class<T> persistentClass;
@SuppressWarnings("unchecked")
public GenericDaoImpl() {
super();
logger.debug("Building ...");
this.persistentClass = (Class<T>) ((ParameterizedType) getClass()
.getGenericSuperclass()).getActualTypeArguments()[0];
}
public abstract void setSessionFactory(SessionFactory sessionFactory);
public abstract Session createHibernateSession();
/*
* (non-Javadoc)
*
* @see net.cinesystem.persistence.GenericDao#findByExample(java.lang.Object)
*/
@SuppressWarnings("unchecked")
public List<T> findByExample(T example) {
return this.hibernateTemplate.findByCriteria(this.mountCriteria(example));
}
/**
* This method is responsable for mount a criteria using the param object
*
* @param example
* @return DetachedCriteria
*/
private DetachedCriteria mountCriteria(T example) {
return DetachedCriteria.forClass(this.persistentClass).add(
Example.create(example).enableLike(MatchMode.ANYWHERE)
.ignoreCase().setPropertySelector(this));
}
// Another hided methods
}
Full stack trace of any exception that occurs:
There is not exception. The result is every time the same when I used the profile in the filter.
When I dont use the profile in the filter, the result is right, but if i choose a profile for search, the select returns all users.
Name and version of the database you are using:
PostGreSQL 8
The generated SQL (show_sql=true):
Hibernate:
/* criteria query */ select
this_.id as id0_1_,
this_.fullName as fullName0_1_,
this_.login as login0_1_,
this_.password as password0_1_,
this_.id_profile as id5_0_1_,
profile2_.id_profile as id1_1_0_,
profile2_.description as descript2_1_0_
from
t_user this_
left outer join
t_profile profile2_
on this_.id_profile=profile2_.id_profile
where
(
1=1
)
Debug level Hibernate log excerpt:
[2007-09-26 02:31:42,078][openConnection] DEBUG (ConnectionManager.java:421) opening JDBC connection
[2007-09-26 02:31:42,078][getConnectionFromDriverManager] DEBUG (DriverManagerDataSource.java:289) Creating new JDBC Connection to [jdbc:postgresql://localhost:5432/cinesystem?charSet=LATIN1]
[2007-09-26 02:31:42,125][log] DEBUG (AbstractBatcher.java:401)
/* load net.cinesystem.model.bean.Profile */ select
profile0_.id_profile as id1_1_0_,
profile0_.description as descript2_1_0_
from
t_profile profile0_
where
profile0_.id_profile=?
Hibernate:
/* load net.cinesystem.model.bean.Profile */ select
profile0_.id_profile as id1_1_0_,
profile0_.description as descript2_1_0_
from
t_profile profile0_
where
profile0_.id_profile=?
[2007-09-26 02:31:42,125][getPreparedStatement] DEBUG (AbstractBatcher.java:484) preparing statement
[2007-09-26 02:31:42,125][nullSafeSet] DEBUG (NullableType.java:133) binding '2' to parameter: 1
[2007-09-26 02:31:42,125][logOpenResults] DEBUG (AbstractBatcher.java:382) about to open ResultSet (open ResultSets: 0, globally: 0)
[2007-09-26 02:31:42,125][doQuery] DEBUG (Loader.java:694) processing result set
[2007-09-26 02:31:42,125][doQuery] DEBUG (Loader.java:699) result set row: 0
[2007-09-26 02:31:42,125][getRow] DEBUG (Loader.java:1173) result row: EntityKey[net.cinesystem.model.bean.Profile#2]
[2007-09-26 02:31:42,125][loadFromResultSet] DEBUG (Loader.java:1355) Initializing object from ResultSet: [net.cinesystem.model.bean.Profile#2]
[2007-09-26 02:31:42,125][hydrate] DEBUG (AbstractEntityPersister.java:2031) Hydrating entity: [net.cinesystem.model.bean.Profile#2]
[2007-09-26 02:31:42,125][nullSafeGet] DEBUG (NullableType.java:172) returning 'parametro.security.level.2' as column: descript2_1_0_
[2007-09-26 02:31:42,140][doQuery] DEBUG (Loader.java:721) done processing result set (1 rows)
[2007-09-26 02:31:42,140][logCloseResults] DEBUG (AbstractBatcher.java:389) about to close ResultSet (open ResultSets: 1, globally: 1)
[2007-09-26 02:31:42,140][logClosePreparedStatement] DEBUG (AbstractBatcher.java:374) about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
[2007-09-26 02:31:42,140][closePreparedStatement] DEBUG (AbstractBatcher.java:533) closing statement
[2007-09-26 02:31:42,140][initializeEntitiesAndCollections] DEBUG (Loader.java:851) total objects hydrated: 1
[2007-09-26 02:31:42,140][initializeEntity] DEBUG (TwoPhaseLoad.java:107) resolving associations for [net.cinesystem.model.bean.Profile#2]
[2007-09-26 02:31:42,140][locateLoadingCollection] DEBUG (LoadContexts.java:110) creating collection wrapper:[net.cinesystem.model.bean.Profile.users#2]
[2007-09-26 02:31:42,140][initializeEntity] DEBUG (TwoPhaseLoad.java:206) done materializing entity [net.cinesystem.model.bean.Profile#2]
[2007-09-26 02:31:42,140][initializeNonLazyCollections] DEBUG (StatefulPersistenceContext.java:787) initializing non-lazy collections
[2007-09-26 02:31:42,140][loadEntity] DEBUG (Loader.java:1883) done entity load
[2007-09-26 02:31:42,140][afterNontransactionalQuery] DEBUG (JDBCContext.java:233) after autocommit
[2007-09-26 02:31:42,140][afterTransaction] DEBUG (ConnectionManager.java:302) transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
[2007-09-26 02:31:42,140][afterTransactionCompletion] DEBUG (SessionImpl.java:422) after transaction completion
[2007-09-26 02:31:42,140][flushIfNecessary] DEBUG (HibernateAccessor.java:389) Eagerly flushing Hibernate session
[2007-09-26 02:31:42,140][flushEverythingToExecutions] DEBUG (AbstractFlushingEventListener.java:58) flushing session
[2007-09-26 02:31:42,140][prepareEntityFlushes] DEBUG (AbstractFlushingEventListener.java:111) processing flush-time cascades
[2007-09-26 02:31:42,140][prepareCollectionFlushes] DEBUG (AbstractFlushingEventListener.java:154) dirty checking collections
[2007-09-26 02:31:42,140][flushEntities] DEBUG (AbstractFlushingEventListener.java:171) Flushing entities and processing referenced collections
[2007-09-26 02:31:42,140][processReachableCollection] DEBUG (Collections.java:176) Collection found: [net.cinesystem.model.bean.Profile.users#2], was: [net.cinesystem.model.bean.Profile.users#2] (uninitialized)
[2007-09-26 02:31:42,140][flushCollections] DEBUG (AbstractFlushingEventListener.java:210) Processing unreferenced collections
[2007-09-26 02:31:42,140][flushCollections] DEBUG (AbstractFlushingEventListener.java:224) Scheduling collection removes/(re)creates/updates
[2007-09-26 02:31:42,140][flushEverythingToExecutions] DEBUG (AbstractFlushingEventListener.java:85) Flushed: 0 insertions, 0 updates, 0 deletions to 1 objects
[2007-09-26 02:31:42,140][flushEverythingToExecutions] DEBUG (AbstractFlushingEventListener.java:91) Flushed: 0 (re)creations, 0 updates, 0 removals to 1 collections
[2007-09-26 02:31:42,140][toString] DEBUG (Printer.java:83) listing entities:
[2007-09-26 02:31:42,140][toString] DEBUG (Printer.java:90) net.cinesystem.model.bean.Profile{id=2, users=<uninitialized>, description=parametro.security.level.2}
[2007-09-26 02:31:42,140][performExecutions] DEBUG (AbstractFlushingEventListener.java:290) executing flush
[2007-09-26 02:31:42,140][flushBeginning] DEBUG (ConnectionManager.java:469) registering flush begin
[2007-09-26 02:31:42,140][flushEnding] DEBUG (ConnectionManager.java:478) registering flush end
[2007-09-26 02:31:42,140][postFlush] DEBUG (AbstractFlushingEventListener.java:321) post flush
[2007-09-26 02:31:42,140][closeSession] DEBUG (SessionFactoryUtils.java:772) Closing Hibernate Session
[2007-09-26 02:31:42,140][close] DEBUG (SessionImpl.java:273) closing session
[2007-09-26 02:31:42,140][cleanup] DEBUG (ConnectionManager.java:380) performing cleanup
[2007-09-26 02:31:42,140][closeConnection] DEBUG (ConnectionManager.java:441) releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
[2007-09-26 02:31:42,140][afterTransactionCompletion] DEBUG (JDBCContext.java:215) after transaction completion
[2007-09-26 02:31:42,156][afterTransaction] DEBUG (ConnectionManager.java:302) transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
[2007-09-26 02:31:42,156][afterTransactionCompletion] DEBUG (SessionImpl.java:422) after transaction completion
[2007-09-26 02:31:42,156][getUserRules] DEBUG (SpringBeanFactory.java:63) Getting userRules
[2007-09-26 02:31:42,156][getBean] DEBUG (SpringBeanFactory.java:58) Getting bean userRules
[2007-09-26 02:31:42,156][getBean] DEBUG (AbstractBeanFactory.java:203) Returning cached instance of singleton bean 'userRules'
[2007-09-26 02:31:42,156][doGetSession] DEBUG (SessionFactoryUtils.java:316) Opening Hibernate Session
[2007-09-26 02:31:42,156][<init>] DEBUG (SessionImpl.java:220) opened session at timestamp: 4877454140030976
[2007-09-26 02:31:42,156][logOpenPreparedStatement] DEBUG (AbstractBatcher.java:366) about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
[2007-09-26 02:31:42,156][openConnection] DEBUG (ConnectionManager.java:421) opening JDBC connection
[2007-09-26 02:31:42,156][getConnectionFromDriverManager] DEBUG (DriverManagerDataSource.java:289) Creating new JDBC Connection to [jdbc:postgresql://localhost:5432/cinesystem?charSet=LATIN1]
[2007-09-26 02:31:42,187][log] DEBUG (AbstractBatcher.java:401)
/* criteria query */ select
this_.id as id0_1_,
this_.fullName as fullName0_1_,
this_.login as login0_1_,
this_.password as password0_1_,
this_.id_profile as id5_0_1_,
profile2_.id_profile as id1_1_0_,
profile2_.description as descript2_1_0_
from
t_user this_
left outer join
t_profile profile2_
on this_.id_profile=profile2_.id_profile
where
(
1=1
)
Hibernate:
/* criteria query */ select
this_.id as id0_1_,
this_.fullName as fullName0_1_,
this_.login as login0_1_,
this_.password as password0_1_,
this_.id_profile as id5_0_1_,
profile2_.id_profile as id1_1_0_,
profile2_.description as descript2_1_0_
from
t_user this_
left outer join
t_profile profile2_
on this_.id_profile=profile2_.id_profile
where
(
1=1
)
[2007-09-26 02:31:42,187][getPreparedStatement] DEBUG (AbstractBatcher.java:484) preparing statement
[2007-09-26 02:31:42,203][logOpenResults] DEBUG (AbstractBatcher.java:382) about to open ResultSet (open ResultSets: 0, globally: 0)
[2007-09-26 02:31:42,203][doQuery] DEBUG (Loader.java:694) processing result set
[2007-09-26 02:31:42,203][doQuery] DEBUG (Loader.java:699) result set row: 0
[2007-09-26 02:31:42,203][nullSafeGet] DEBUG (NullableType.java:172) returning '1' as column: id1_1_0_
[2007-09-26 02:31:42,203][nullSafeGet] DEBUG (NullableType.java:172) returning '1' as column: id0_1_
[2007-09-26 02:31:42,203][getRow] DEBUG (Loader.java:1173) result row: EntityKey[net.cinesystem.model.bean.Profile#1], EntityKey[net.cinesystem.model.bean.User#1]
[2007-09-26 02:31:42,203][loadFromResultSet] DEBUG (Loader.java:1355) Initializing object from ResultSet: [net.cinesystem.model.bean.Profile#1]
[2007-09-26 02:31:42,203][hydrate] DEBUG (AbstractEntityPersister.java:2031) Hydrating entity: [net.cinesystem.model.bean.Profile#1]
[2007-09-26 02:31:42,203][nullSafeGet] DEBUG (NullableType.java:172) returning 'parametro.security.level.1' as column: descript2_1_0_
[2007-09-26 02:31:42,203][loadFromResultSet] DEBUG (Loader.java:1355) Initializing object from ResultSet: [net.cinesystem.model.bean.User#1]
[2007-09-26 02:31:42,203][hydrate] DEBUG (AbstractEntityPersister.java:2031) Hydrating entity: [net.cinesystem.model.bean.User#1]
[2007-09-26 02:31:42,203][nullSafeGet] DEBUG (NullableType.java:172) returning 'Márcio Barroso' as column: fullName0_1_
[2007-09-26 02:31:42,203][nullSafeGet] DEBUG (NullableType.java:172) returning 'marcio' as column: login0_1_
[2007-09-26 02:31:42,203][nullSafeGet] DEBUG (NullableType.java:172) returning 'tomaty' as column: password0_1_
[2007-09-26 02:31:42,203][nullSafeGet] DEBUG (NullableType.java:172) returning '1' as column: id5_0_1_
[2007-09-26 02:31:42,203][doQuery] DEBUG (Loader.java:721) done processing result set (1 rows)
[2007-09-26 02:31:42,203][logCloseResults] DEBUG (AbstractBatcher.java:389) about to close ResultSet (open ResultSets: 1, globally: 1)
[2007-09-26 02:31:42,203][logClosePreparedStatement] DEBUG (AbstractBatcher.java:374) about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
[2007-09-26 02:31:42,203][closePreparedStatement] DEBUG (AbstractBatcher.java:533) closing statement
[2007-09-26 02:31:42,203][initializeEntitiesAndCollections] DEBUG (Loader.java:851) total objects hydrated: 2
[2007-09-26 02:31:42,203][initializeEntity] DEBUG (TwoPhaseLoad.java:107) resolving associations for [net.cinesystem.model.bean.Profile#1]
[2007-09-26 02:31:42,203][locateLoadingCollection] DEBUG (LoadContexts.java:110) creating collection wrapper:[net.cinesystem.model.bean.Profile.users#1]
[2007-09-26 02:31:42,203][initializeEntity] DEBUG (TwoPhaseLoad.java:206) done materializing entity [net.cinesystem.model.bean.Profile#1]
[2007-09-26 02:31:42,203][initializeEntity] DEBUG (TwoPhaseLoad.java:107) resolving associations for [net.cinesystem.model.bean.User#1]
[2007-09-26 02:31:42,203][proxyOrLoad] DEBUG (DefaultLoadEventListener.java:171) loading entity: [net.cinesystem.model.bean.Profile#1]
[2007-09-26 02:31:42,218][doLoad] DEBUG (DefaultLoadEventListener.java:332) attempting to resolve: [net.cinesystem.model.bean.Profile#1]
[2007-09-26 02:31:42,218][doLoad] DEBUG (DefaultLoadEventListener.java:349) resolved object in session cache: [net.cinesystem.model.bean.Profile#1]
[2007-09-26 02:31:42,218][initializeEntity] DEBUG (TwoPhaseLoad.java:206) done materializing entity [net.cinesystem.model.bean.User#1]
[2007-09-26 02:31:42,218][initializeNonLazyCollections] DEBUG (StatefulPersistenceContext.java:787) initializing non-lazy collections
[2007-09-26 02:31:42,218][afterNontransactionalQuery] DEBUG (JDBCContext.java:233) after autocommit
[2007-09-26 02:31:42,218][afterTransaction] DEBUG (ConnectionManager.java:302) transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
[2007-09-26 02:31:42,218][afterTransactionCompletion] DEBUG (SessionImpl.java:422) after transaction completion
[2007-09-26 02:31:42,218][flushIfNecessary] DEBUG (HibernateAccessor.java:389) Eagerly flushing Hibernate session
[2007-09-26 02:31:42,218][flushEverythingToExecutions] DEBUG (AbstractFlushingEventListener.java:58) flushing session
[2007-09-26 02:31:42,218][prepareEntityFlushes] DEBUG (AbstractFlushingEventListener.java:111) processing flush-time cascades
[2007-09-26 02:31:42,218][prepareCollectionFlushes] DEBUG (AbstractFlushingEventListener.java:154) dirty checking collections
[2007-09-26 02:31:42,218][flushEntities] DEBUG (AbstractFlushingEventListener.java:171) Flushing entities and processing referenced collections
[2007-09-26 02:31:42,218][processReachableCollection] DEBUG (Collections.java:176) Collection found: [net.cinesystem.model.bean.Profile.users#1], was: [net.cinesystem.model.bean.Profile.users#1] (uninitialized)
[2007-09-26 02:31:42,218][flushCollections] DEBUG (AbstractFlushingEventListener.java:210) Processing unreferenced collections
[2007-09-26 02:31:42,218][flushCollections] DEBUG (AbstractFlushingEventListener.java:224) Scheduling collection removes/(re)creates/updates
[2007-09-26 02:31:42,218][flushEverythingToExecutions] DEBUG (AbstractFlushingEventListener.java:85) Flushed: 0 insertions, 0 updates, 0 deletions to 2 objects
[2007-09-26 02:31:42,218][flushEverythingToExecutions] DEBUG (AbstractFlushingEventListener.java:91) Flushed: 0 (re)creations, 0 updates, 0 removals to 1 collections
[2007-09-26 02:31:42,218][toString] DEBUG (Printer.java:83) listing entities:
[2007-09-26 02:31:42,218][toString] DEBUG (Printer.java:90) net.cinesystem.model.bean.Profile{id=1, users=<uninitialized>, description=parametro.security.level.1}
[2007-09-26 02:31:42,218][toString] DEBUG (Printer.java:90) net.cinesystem.model.bean.User{id=1, login=marcio, fullName=Márcio Barroso, password=tomaty, profile=net.cinesystem.model.bean.Profile#1}
[2007-09-26 02:31:42,218][performExecutions] DEBUG (AbstractFlushingEventListener.java:290) executing flush
[2007-09-26 02:31:42,218][flushBeginning] DEBUG (ConnectionManager.java:469) registering flush begin
[2007-09-26 02:31:42,218][flushEnding] DEBUG (ConnectionManager.java:478) registering flush end
[2007-09-26 02:31:42,218][postFlush] DEBUG (AbstractFlushingEventListener.java:321) post flush
[2007-09-26 02:31:42,218][closeSession] DEBUG (SessionFactoryUtils.java:772) Closing Hibernate Session
[2007-09-26 02:31:42,218][close] DEBUG (SessionImpl.java:273) closing session
[2007-09-26 02:31:42,218][cleanup] DEBUG (ConnectionManager.java:380) performing cleanup
[2007-09-26 02:31:42,218][closeConnection] DEBUG (ConnectionManager.java:441) releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
[2007-09-26 02:31:42,218][afterTransactionCompletion] DEBUG (JDBCContext.java:215) after transaction completion
[2007-09-26 02:31:42,218][afterTransaction] DEBUG (ConnectionManager.java:302) transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
[2007-09-26 02:31:42,234][afterTransactionCompletion] DEBUG (SessionImpl.java:422) after transaction completion
[2007-09-26 02:31:42,234][stoped] DEBUG (CineSystemInternalFrame.java:40) Stoped
[2007-09-26 02:31:42,234][stoped] DEBUG (CineSystemInternalFrame.java:40) Stoped