Hi guys,
sorry for my departure, i was tied up with other issues. ignore the previous problem that was my error, but the underlying issue remains, how to filter a a collection to find out if it contains an object...
here's a simple test case for the suggestion you gave:
Code:
<class name="eg.Parent">
<id name="id">
<generator class="native"/>
</id>
<set name="children" lazy="true" table="childset">
<key column="parent_id"/>
<many-to-many class="eg.Child"
column="child_id"/>
</set>
</class>
<class name="eg.Child">
<id name="id">
<generator class="native"/>
</id>
<property name="name"/>
</class>
Code:
Session session = factory.openSession();
Transaction transaction = null;
try {
session = factory.openSession();
transaction = session.beginTransaction();
Child child = new Child();
session.save(child);
Parent parent = new Parent();
Set children = new HashSet();
children.add(child);
parent.setChildren(children);
session.save(parent);
session.flush();
transaction.commit();
session.close();
session = factory.openSession();
transaction = session.beginTransaction();
parent = (Parent) session.load(Parent.class, parent.getId());
child = (Child) session.load(Child.class, child.getId());
Collection results = session.filter(parent.getChildren(), "where this = ?", child, Hibernate.OBJECT);
System.out.println("Success, child is in collection");
session.flush();
transaction.commit();
} catch (HibernateException e) {
e.printStackTrace();
if (transaction != null) {
transaction.rollback();
}
} finally {
if (session != null) {
session.close();
}
}
And the error:
Code:
Hibernate: select hibernate_sequence.nextval from dual
Hibernate: select hibernate_sequence.nextval from dual
Hibernate: insert into Child (name, id) values (?, ?)
Hibernate: insert into Parent (id) values (?)
Hibernate: insert into childset (parent_id, child_id) values (?, ?)
Hibernate: select parent0_.id as id0_ from Parent parent0_ where parent0_.id=?
Hibernate: select child0_.id as id0_, child0_.name as name0_ from Child child0_ where child0_.id=?
Hibernate: select this.id as id, this.name as name from childset children0_ inner join Child this on children0_.child_id=this.id where children0_.parent_id = ? and ((this.id=? ))
2004-12-22 10:39:35,515 WARN net.sf.hibernate.util.JDBCExceptionReporter - SQL Error: 1006, SQLState: 72000
2004-12-22 10:39:35,515 ERROR net.sf.hibernate.util.JDBCExceptionReporter - ORA-01006: bind variable does not exist
2004-12-22 10:39:35,515 WARN net.sf.hibernate.util.JDBCExceptionReporter - SQL Error: 1006, SQLState: 72000
2004-12-22 10:39:35,515 ERROR net.sf.hibernate.util.JDBCExceptionReporter - ORA-01006: bind variable does not exist
net.sf.hibernate.exception.GenericJDBCException: Could not execute query
at net.sf.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:90)
at net.sf.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:79)
at net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:30)
at net.sf.hibernate.impl.SessionImpl.convert(SessionImpl.java:4110)
at net.sf.hibernate.impl.SessionImpl.filter(SessionImpl.java:3561)
at net.sf.hibernate.impl.SessionImpl.filter(SessionImpl.java:3447)
at eg.Test.main(Test.java:86)
Caused by: java.sql.SQLException: ORA-01006: bind variable does not exist
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:582)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1986)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteDescribe(TTC7Protocol.java:880)
at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:2516)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2850)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:609)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:537)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:88)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:875)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:269)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.filter(SessionImpl.java:3558)
... 2 more