-->
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.  [ 4 posts ] 
Author Message
 Post subject: Mapping Question Using Set
PostPosted: Fri Mar 10, 2006 11:09 am 
Beginner
Beginner

Joined: Thu Dec 15, 2005 12:02 pm
Posts: 23
Hello,
I have a Users table with a primary key of "user_id". A user may have many passwords. I have a password table with a foreign key of "user_id".

I have the mappings below for each table. I am trying to retrieve information about the users table and also bring back a set of the passwords for the said user.

When I get the Set from the Users object, it says I only have 1 password object. But when I watch the log, I can clearly see (below) that it is retrieving 4 passwords (this is correct) for my username.

I am creating the src file by using the hbm2Java function.

Here is the java file for Users followed by Password:

Thank you
Scott




package com.mb.purcell;



import java.io.Serializable;
import java.util.Set;
import org.apache.commons.lang.builder.ToStringBuilder;




/**
* Table to hold user information
*
*/

public class Users implements Serializable {



/** identifier field */

private int user_id;



/** nullable persistent field */

private String username;



/** nullable persistent field */

private String firstname;



/** nullable persistent field */

private String lastname;



/** persistent field */

private Set password;



/** full constructor */

public Users(String username, String firstname, String lastname, Set password) {

this.username = username;

this.firstname = firstname;

this.lastname = lastname;

this.password = password;

}



/** default constructor */

public Users() {

}



/** minimal constructor */

public Users(Set password) {

this.password = password;

}



public int getUser_id() {

return this.user_id;

}



public void setUser_id(int user_id) {

this.user_id = user_id;

}



/**
* Username
*/

public String getUsername() {

return this.username;

}



public void setUsername(String username) {

this.username = username;

}



/**
* Firstname
*/

public String getFirstname() {

return this.firstname;

}



public void setFirstname(String firstname) {

this.firstname = firstname;

}



/**
* Lastname
*/

public String getLastname() {

return this.lastname;

}



public void setLastname(String lastname) {

this.lastname = lastname;

}



public Set getPassword() {

return this.password;

}



public void setPassword(Set password) {

this.password = password;

}



public String toString() {

return new ToStringBuilder(this)

.append("user_id", getUser_id())

.toString();

}



}



package com.mb.purcell;



import java.io.Serializable;
import org.apache.commons.lang.builder.ToStringBuilder;




/**
* Object holds password information.
*
*/

public class Password implements Serializable {



/** identifier field */

private int user_id;



/** nullable persistent field */

private String password;



/** full constructor */

public Password(String password) {

this.password = password;

}



/** default constructor */

public Password() {

}



public int getUser_id() {

return this.user_id;

}



public void setUser_id(int user_id) {

this.user_id = user_id;

}



/**
* Password
*/

public String getPassword() {

return this.password;

}



public void setPassword(String password) {

this.password = password;

}



public String toString() {

return new ToStringBuilder(this)

.append("user_id", getUser_id())

.toString();

}



}




Hibernate version: 3.0


Mapping documents:
Users:
<?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="com.mb.purcell.Users" table="USERS" >
<meta attribute="class-description">
Table to hold user information
</meta>

<id name="user_id" column="USER_ID" type="int">
<generator class="identity"/>
</id>

<property name="username" column="username" type="string" >
<meta attribute="field-description">Username</meta>
</property>

<property name="firstname" column="firstname" type="string" >
<meta attribute="field-description">Firstname</meta>
</property>


<property name="lastname" column="lastname" type="string" >
<meta attribute="field-description">Lastname</meta>
</property>


<set name="Password" lazy="true" inverse="true" cascade="all-delete-orphan">
<key column="USER_ID" />
<one-to-many class="com.mb.purcell.Password" />
</set>

</class>
</hibernate-mapping>


Password:
<?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="com.mb.purcell.Password" table="PASSWORD" >
<meta attribute="class-description">
Object holds password information.
</meta>

<id name="user_id" column="USER_ID" type="int">
<generator class="identity"/>
</id>

<property name="password" column="password" type="string" >
<meta attribute="field-description">Password</meta>
</property>

</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
public class QueryTest {


public static void main(String[] args) throws Exception
{
Configuration config = new Configuration();
config.addClass(Users.class);
config.addClass(Password.class);
SessionFactory sessionFactory = config.buildSessionFactory();
Session session = sessionFactory.openSession();

/* session.createCriteria(Users.class)
.add( Expression.eq("username", "spurcell"));
*/
String query = "FROM Users user where username = 'spurcell'";

// String query = "from com.mb.purcell.Users as u order by u.username ASC";

try {
List users = session.createQuery(query).list();

for (ListIterator iter = users.listIterator();
iter.hasNext(); ) {
Users aUser = (Users)iter.next();
System.out.println("User: \"" + aUser.getUsername());
Set prop = aUser.getPassword();
System.out.println("XX " + prop.size());
Iterator it = prop.iterator();
while(it.hasNext()){
Password pw = (Password)it.next();
String password = pw.getPassword();
System.out.println("password=" + password);
}

}
} finally {
session.close();
}
sessionFactory.close();
}
}


Full stack trace of any exception that occurs:

Name and version of the database you are using:
Oracle 9i

The generated SQL (show_sql=true):

[java] 09:01:01,928 WARN Configurator:125 - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in t
he classpath: jar:file:/C:/hib/lib/ehcache-0.9.jar!/ehcache-failsafe.xml
[java] 09:01:02,225 DEBUG BasicEntityPersister:2234 - Static SQL for entity: com.mb.purcell.Password
[java] 09:01:02,225 DEBUG BasicEntityPersister:2236 - Version select: select USER_ID from PASSWORD where USER_ID =?
[java] 09:01:02,225 DEBUG BasicEntityPersister:2237 - Snapshot select: select password_.USER_ID, password_.password as passw
ord1_ from PASSWORD password_ where password_.USER_ID=?
[java] 09:01:02,225 DEBUG BasicEntityPersister:2239 - Insert 0: insert into PASSWORD (password, USER_ID) values (?, ?)
[java] 09:01:02,225 DEBUG BasicEntityPersister:2240 - Update 0: update PASSWORD set password=? where USER_ID=?
[java] 09:01:02,225 DEBUG BasicEntityPersister:2241 - Delete 0: delete from PASSWORD where USER_ID=?
[java] 09:01:02,225 DEBUG BasicEntityPersister:2244 - Identity insert: insert into PASSWORD (password) values (?)
[java] 09:01:02,288 DEBUG BasicEntityPersister:2234 - Static SQL for entity: com.mb.purcell.Users
[java] 09:01:02,288 DEBUG BasicEntityPersister:2236 - Version select: select USER_ID from USERS where USER_ID =?
[java] 09:01:02,288 DEBUG BasicEntityPersister:2237 - Snapshot select: select users_.USER_ID, users_.username as username0_,
users_.firstname as firstname0_, users_.lastname as lastname0_ from USERS users_ where users_.USER_ID=?
[java] 09:01:02,288 DEBUG BasicEntityPersister:2239 - Insert 0: insert into USERS (username, firstname, lastname, USER_ID) v
alues (?, ?, ?, ?)
[java] 09:01:02,288 DEBUG BasicEntityPersister:2240 - Update 0: update USERS set username=?, firstname=?, lastname=? where U
SER_ID=?
[java] 09:01:02,288 DEBUG BasicEntityPersister:2241 - Delete 0: delete from USERS where USER_ID=?
[java] 09:01:02,288 DEBUG BasicEntityPersister:2244 - Identity insert: insert into USERS (username, firstname, lastname) val
ues (?, ?, ?)
[java] 09:01:02,303 DEBUG AbstractCollectionPersister:479 - Static SQL for collection: com.mb.purcell.Users.Password
[java] 09:01:02,303 DEBUG AbstractCollectionPersister:480 - Row insert: update PASSWORD set USER_ID=? where USER_ID=?
[java] 09:01:02,303 DEBUG AbstractCollectionPersister:482 - Row delete: update PASSWORD set USER_ID=null where USER_ID=? and
USER_ID=?
[java] 09:01:02,303 DEBUG AbstractCollectionPersister:483 - One-shot delete: update PASSWORD set USER_ID=null where USER_ID=
?
[java] 09:01:02,350 DEBUG EntityLoader:120 - Static select for entity com.mb.purcell.Password: select password0_.USER_ID as U
SER1_0_, password0_.password as password1_0_ from PASSWORD password0_ where password0_.USER_ID=?
[java] 09:01:02,350 DEBUG EntityLoader:120 - Static select for entity com.mb.purcell.Password: select password0_.USER_ID as U
SER1_0_, password0_.password as password1_0_ from PASSWORD password0_ where password0_.USER_ID=?
[java] 09:01:02,350 DEBUG EntityLoader:120 - Static select for entity com.mb.purcell.Password: select password0_.USER_ID as U
SER1_0_, password0_.password as password1_0_ from PASSWORD password0_ where password0_.USER_ID=? for update
[java] 09:01:02,350 DEBUG EntityLoader:120 - Static select for entity com.mb.purcell.Password: select password0_.USER_ID as U
SER1_0_, password0_.password as password1_0_ from PASSWORD password0_ where password0_.USER_ID=? for update nowait
[java] 09:01:02,350 DEBUG EntityLoader:120 - Static select for entity com.mb.purcell.Users: select users0_.USER_ID as USER1_0
_, users0_.username as username0_0_, users0_.firstname as firstname0_0_, users0_.lastname as lastname0_0_ from USERS users0_ where
users0_.USER_ID=?
[java] 09:01:02,366 DEBUG EntityLoader:120 - Static select for entity com.mb.purcell.Users: select users0_.USER_ID as USER1_0
_, users0_.username as username0_0_, users0_.firstname as firstname0_0_, users0_.lastname as lastname0_0_ from USERS users0_ where
users0_.USER_ID=?
[java] 09:01:02,366 DEBUG EntityLoader:120 - Static select for entity com.mb.purcell.Users: select users0_.USER_ID as USER1_0
_, users0_.username as username0_0_, users0_.firstname as firstname0_0_, users0_.lastname as lastname0_0_ from USERS users0_ where
users0_.USER_ID=? for update
[java] 09:01:02,366 DEBUG EntityLoader:120 - Static select for entity com.mb.purcell.Users: select users0_.USER_ID as USER1_0
_, users0_.username as username0_0_, users0_.firstname as firstname0_0_, users0_.lastname as lastname0_0_ from USERS users0_ where
users0_.USER_ID=? for update nowait
[java] 09:01:02,366 DEBUG OneToManyLoader:98 - Static select for one-to-many com.mb.purcell.Users.Password: select password0_
.USER_ID as USER1___, password0_.USER_ID as USER1_0_, password0_.password as password1_0_ from PASSWORD password0_ where password0
_.USER_ID=?
[java] 09:01:02,366 DEBUG SessionFactoryObjectFactory:39 - initializing class SessionFactoryObjectFactory
[java] 09:01:02,366 DEBUG SessionFactoryObjectFactory:76 - registered: 4028c2c709e4acc60109e4acc91e0000 (unnamed)
[java] 09:01:02,366 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
[java] 09:01:02,366 DEBUG SessionFactoryImpl:249 - instantiated session factory
[java] 09:01:02,381 INFO SessionFactoryImpl:366 - Checking 0 named queries
[java] 09:01:02,413 DEBUG SessionImpl:229 - opened session at timestamp: 4677643724312576
[java] 09:01:02,428 DEBUG SessionImpl:774 - find: FROM Users user where username = 'spurcell'
[java] 09:01:02,428 DEBUG QueryParameters:220 - named parameters: {}
[java] 09:01:02,491 DEBUG QueryTranslatorImpl:207 - parse() - HQL: FROM com.mb.purcell.Users user where username = 'spurcell'

[java] 09:01:02,506 DEBUG AST:223 - --- HQL AST ---
[java] \-[QUERY] 'query'
[java] +-[SELECT_FROM] 'SELECT_FROM'
[java] | \-[FROM] 'FROM'
[java] | +-[DOT] '.'
[java] | | +-[DOT] '.'
[java] | | | +-[DOT] '.'
[java] | | | | +-[IDENT] 'com'
[java] | | | | \-[IDENT] 'mb'
[java] | | | \-[IDENT] 'purcell'
[java] | | \-[IDENT] 'Users'
[java] | \-[ALIAS] 'user'
[java] \-[WHERE] 'where'
[java] \-[EQ] '='
[java] +-[IDENT] 'username'
[java] \-[QUOTED_STRING] ''spurcell''

[java] 09:01:02,506 DEBUG ErrorCounter:72 - throwQueryException() : no errors
[java] 09:01:02,553 DEBUG HqlSqlBaseWalker:119 - query() << begin, level = 1
[java] 09:01:02,647 DEBUG FromElement:79 - FromClause{level=1} : com.mb.purcell.Users (user) -> users0_
[java] 09:01:02,647 DEBUG HqlSqlBaseWalker:124 - query() : finishing up , level = 1
[java] 09:01:02,647 DEBUG HqlSqlWalker:328 - processQuery() : ( SELECT ( FromClause{level=1} USERS users0_ ) ( where ( = use
rname 'spurcell' ) ) )
[java] 09:01:02,663 DEBUG HqlSqlWalker:448 - Derived SELECT clause created.
[java] 09:01:02,663 DEBUG JoinProcessor:112 - Using FROM fragment [USERS users0_]
[java] 09:01:02,663 DEBUG HqlSqlBaseWalker:127 - query() >> end, level = 1
[java] 09:01:02,678 DEBUG AST:193 - --- SQL AST ---
[java] \-[SELECT] QueryNode: 'SELECT' querySpaces (USERS)
[java] +-[SELECT_CLAUSE] SelectClause: '{derived select clause}'
[java] | +-[SELECT_EXPR] SelectExpressionImpl: 'users0_.USER_ID as USER1_' {FromElement{explicit,not a collection join,c
lassAlias=user,role=null,tableName=USERS,tableAlias=users0_,colums={,className=com.mb.purcell.Users}}}
[java] | \-[SQL_TOKEN] SqlFragment: 'users0_.username as username0_, users0_.firstname as firstname0_, users0_.lastname
as lastname0_'
[java] +-[FROM] FromClause: 'FROM' FromClause{level=1, fromElementCounter=1, fromElements=1, fromElementByClassAlias=[use
r], fromElementByTableAlias=[users0_], fromElementsByPath=[], collectionJoinFromElementsByPath=[], impliedElements=[]}
[java] | \-[FROM_FRAGMENT] FromElement: 'USERS users0_' FromElement{explicit,not a collection join,classAlias=user,role=
null,tableName=USERS,tableAlias=users0_,colums={,className=com.mb.purcell.Users}}
[java] \-[WHERE] SqlNode: 'where'
[java] \-[EQ] SqlNode: '='
[java] +-[IDENT] IdentNode: 'username' {originalText=username}
[java] \-[QUOTED_STRING] LiteralNode: ''spurcell''

[java] 09:01:02,678 DEBUG ErrorCounter:72 - throwQueryException() : no errors
[java] 09:01:02,694 DEBUG QueryTranslatorImpl:177 - HQL: FROM com.mb.purcell.Users user where username = 'spurcell'
[java] 09:01:02,694 DEBUG QueryTranslatorImpl:178 - SQL: select users0_.USER_ID as USER1_, users0_.username as username0_, us
ers0_.firstname as firstname0_, users0_.lastname as lastname0_ from USERS users0_ where (username='spurcell')
[java] 09:01:02,694 DEBUG ErrorCounter:72 - throwQueryException() : no errors
[java] 09:01:02,710 DEBUG AbstractBatcher:276 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
[java] 09:01:02,710 DEBUG AbstractBatcher:408 - opening JDBC connection
[java] 09:01:02,710 DEBUG DriverManagerConnectionProvider:93 - total checked-out connections: 0
[java] 09:01:02,710 DEBUG DriverManagerConnectionProvider:99 - using pooled JDBC connection, pool size: 0
[java] 09:01:02,710 DEBUG SQL:310 - select users0_.USER_ID as USER1_, users0_.username as username0_, users0_.firstname as fi
rstname0_, users0_.lastname as lastname0_ from USERS users0_ where (username='spurcell')
[java] 09:01:02,710 DEBUG AbstractBatcher:364 - preparing statement
[java] 09:01:02,741 DEBUG AbstractBatcher:292 - about to open ResultSet (open ResultSets: 0, globally: 0)
[java] 09:01:02,741 DEBUG Loader:380 - processing result set
[java] 09:01:02,741 DEBUG Loader:385 - result set row: 0
[java] 09:01:02,756 DEBUG Loader:760 - result row: EntityKey[com.mb.purcell.Users#10089383]
[java] 09:01:02,756 DEBUG Loader:905 - Initializing object from ResultSet: [com.mb.purcell.Users#10089383]
[java] 09:01:02,772 DEBUG BasicEntityPersister:1665 - Hydrating entity: [com.mb.purcell.Users#10089383]
[java] 09:01:02,772 DEBUG Loader:404 - done processing result set (1 rows)
[java] 09:01:02,772 DEBUG AbstractBatcher:299 - about to close ResultSet (open ResultSets: 1, globally: 1)
[java] 09:01:02,772 DEBUG AbstractBatcher:284 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
[java] 09:01:02,772 DEBUG AbstractBatcher:392 - closing statement
[java] 09:01:02,772 DEBUG Loader:490 - total objects hydrated: 1
[java] 09:01:02,772 DEBUG TwoPhaseLoad:96 - resolving associations for [com.mb.purcell.Users#10089383]
[java] 09:01:02,788 DEBUG CollectionLoadContext:134 - creating collection wrapper:[com.mb.purcell.Users.Password#10089383]
[java] 09:01:02,788 DEBUG TwoPhaseLoad:167 - done materializing entity [com.mb.purcell.Users#10089383]
[java] 09:01:02,788 DEBUG PersistenceContext:738 - initializing non-lazy collections
[java] User: "spurcell
[java] 09:01:02,788 DEBUG DefaultInitializeCollectionEventListener:42 - initializing collection [com.mb.purcell.Users.Passwor
d#10089383]
[java] 09:01:02,803 DEBUG DefaultInitializeCollectionEventListener:47 - checking second-level cache
[java] 09:01:02,803 DEBUG DefaultInitializeCollectionEventListener:59 - collection not cached
[java] 09:01:02,803 DEBUG Loader:1352 - batch loading collection: [com.mb.purcell.Users.Password#10089383]
[java] 09:01:02,803 DEBUG AbstractBatcher:276 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
[java] 09:01:02,803 DEBUG SQL:310 - select password0_.USER_ID as USER1___, password0_.USER_ID as USER1_0_, password0_.passwor
d as password1_0_ from PASSWORD password0_ where password0_.USER_ID=?
[java] 09:01:02,803 DEBUG AbstractBatcher:364 - preparing statement
[java] 09:01:02,819 DEBUG AbstractBatcher:292 - about to open ResultSet (open ResultSets: 0, globally: 0)
[java] 09:01:02,819 DEBUG Loader:651 - result set contains (possibly empty) collection: [com.mb.purcell.Users.Password#100893
83]
[java] 09:01:02,819 DEBUG CollectionLoadContext:78 - uninitialized collection: initializing
[java] 09:01:02,819 DEBUG Loader:380 - processing result set
[java] 09:01:02,819 DEBUG Loader:385 - result set row: 0
[java] 09:01:02,835 DEBUG Loader:760 - result row: EntityKey[com.mb.purcell.Password#10089383]
[java] 09:01:02,835 DEBUG Loader:905 - Initializing object from ResultSet: [com.mb.purcell.Password#10089383]
[java] 09:01:02,835 DEBUG BasicEntityPersister:1665 - Hydrating entity: [com.mb.purcell.Password#10089383]
[java] 09:01:02,835 DEBUG Loader:592 - found row of collection: [com.mb.purcell.Users.Password#10089383]
[java] 09:01:02,835 DEBUG CollectionLoadContext:105 - reading row
[java] 09:01:02,835 DEBUG DefaultLoadEventListener:193 - loading entity: [com.mb.purcell.Password#10089383]
[java] 09:01:02,835 DEBUG DefaultLoadEventListener:209 - entity found in session cache
[java] 09:01:02,835 DEBUG DefaultLoadEventListener:326 - attempting to resolve: [com.mb.purcell.Password#10089383]
[java] 09:01:02,835 DEBUG DefaultLoadEventListener:335 - resolved object in session cache: [com.mb.purcell.Password#10089383]

[java] 09:01:02,835 DEBUG Loader:385 - result set row: 1
[java] 09:01:02,835 DEBUG Loader:760 - result row: EntityKey[com.mb.purcell.Password#10089383]
[java] 09:01:02,835 DEBUG Loader:592 - found row of collection: [com.mb.purcell.Users.Password#10089383]
[java] 09:01:02,835 DEBUG CollectionLoadContext:105 - reading row
[java] 09:01:02,835 DEBUG DefaultLoadEventListener:193 - loading entity: [com.mb.purcell.Password#10089383]
[java] 09:01:02,835 DEBUG DefaultLoadEventListener:209 - entity found in session cache
[java] 09:01:02,835 DEBUG DefaultLoadEventListener:326 - attempting to resolve: [com.mb.purcell.Password#10089383]
[java] 09:01:02,835 DEBUG DefaultLoadEventListener:335 - resolved object in session cache: [com.mb.purcell.Password#10089383]

[java] 09:01:02,835 DEBUG Loader:385 - result set row: 2
[java] 09:01:02,850 DEBUG Loader:760 - result row: EntityKey[com.mb.purcell.Password#10089383]
[java] 09:01:02,850 DEBUG Loader:592 - found row of collection: [com.mb.purcell.Users.Password#10089383]
[java] 09:01:02,850 DEBUG CollectionLoadContext:105 - reading row
[java] 09:01:02,850 DEBUG DefaultLoadEventListener:193 - loading entity: [com.mb.purcell.Password#10089383]
[java] 09:01:02,850 DEBUG DefaultLoadEventListener:209 - entity found in session cache
[java] 09:01:02,850 DEBUG DefaultLoadEventListener:326 - attempting to resolve: [com.mb.purcell.Password#10089383]
[java] 09:01:02,850 DEBUG DefaultLoadEventListener:335 - resolved object in session cache: [com.mb.purcell.Password#10089383]

[java] 09:01:02,850 DEBUG Loader:385 - result set row: 3
[java] 09:01:02,850 DEBUG Loader:760 - result row: EntityKey[com.mb.purcell.Password#10089383]
[java] 09:01:02,850 DEBUG Loader:592 - found row of collection: [com.mb.purcell.Users.Password#10089383]
[java] 09:01:02,850 DEBUG CollectionLoadContext:105 - reading row
[java] 09:01:02,850 DEBUG DefaultLoadEventListener:193 - loading entity: [com.mb.purcell.Password#10089383]
[java] 09:01:02,866 DEBUG DefaultLoadEventListener:209 - entity found in session cache
[java] 09:01:02,866 DEBUG DefaultLoadEventListener:326 - attempting to resolve: [com.mb.purcell.Password#10089383]
[java] 09:01:02,866 DEBUG DefaultLoadEventListener:335 - resolved object in session cache: [com.mb.purcell.Password#10089383]

[java] 09:01:02,866 DEBUG Loader:404 - done processing result set (4 rows)
[java] 09:01:02,866 DEBUG AbstractBatcher:299 - about to close ResultSet (open ResultSets: 1, globally: 1)
[java] 09:01:02,866 DEBUG AbstractBatcher:284 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
[java] 09:01:02,866 DEBUG AbstractBatcher:392 - closing statement
[java] 09:01:02,866 DEBUG Loader:490 - total objects hydrated: 1
[java] 09:01:02,866 DEBUG TwoPhaseLoad:96 - resolving associations for [com.mb.purcell.Password#10089383]
[java] 09:01:02,866 DEBUG TwoPhaseLoad:167 - done materializing entity [com.mb.purcell.Password#10089383]
[java] 09:01:02,866 DEBUG CollectionLoadContext:239 - 1 collections were found in result set
[java] 09:01:02,866 DEBUG CollectionLoadContext:193 - collection fully initialized: [com.mb.purcell.Users.Password#10089383]
[java] 09:01:02,866 DEBUG CollectionLoadContext:247 - 1 collections initialized
[java] 09:01:02,881 DEBUG PersistenceContext:738 - initializing non-lazy collections
[java] 09:01:02,881 DEBUG Loader:1376 - done loading collection
[java] 09:01:02,881 DEBUG DefaultInitializeCollectionEventListener:61 - collection initialized
[java] XX 1
[java] password=matthew999
[java] 09:01:02,881 DEBUG SessionImpl:246 - closing session
[java] 09:01:02,881 DEBUG AbstractBatcher:423 - closing JDBC connection (open PreparedStatements: 0, globally: 0) (open Resul
tSets: 0, globally: 0)
[java] 09:01:02,881 DEBUG DriverManagerConnectionProvider:129 - returning connection to pool, pool size: 1
[java] 09:01:02,881 DEBUG JDBCContext:213 - after transaction completion
[java] 09:01:02,881 DEBUG SessionImpl:353 - after transaction completion
[java] 09:01:02,881 INFO SessionFactoryImpl:684 - closing
[java] 09:01:02,881 INFO DriverManagerConnectionProvider:147 - cleaning up connection pool: jdbc:oracle:thin:@devweb2.dimens
ions.com:1521:dev


Debug level Hibernate log excerpt:
debug


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 10, 2006 12:15 pm 
Regular
Regular

Joined: Tue Jan 03, 2006 9:52 am
Posts: 52
Location: Zurich
Hello,
There is a problem with the mapping file Password.
You use generator "identity", which means that each entry has a different value (PK). You can therefore not have multiple USER_ID in this table.
You could for instance use a composite element:

Code:
<set name=password table="PASSWORD" >
  <key column="user_id>
  <composite-element class="Password">
    <property name="password" column="password" type="string">
  </composite-element>
</set>


Hope this helps!

Urs


Top
 Profile  
 
 Post subject: Thanks, Cannot Get Valid XML
PostPosted: Fri Mar 10, 2006 12:50 pm 
Beginner
Beginner

Joined: Thu Dec 15, 2005 12:02 pm
Posts: 23
Thanks for the assistance.

I am updating my Password.hbm.xml like so:
<hibernate-mapping>
<class name="com.mb.purcell.Password" table="PASSWORD" >
<meta attribute="class-description">
Object holds password information.
</meta>


<set name="password" table="PASSWORD">
<key column="user_id">
<composite-element class="Password">
<property name="password" column="password" type="string" />
</composite-element>
</key>
</set>



</class>
</hibernate-mapping>


But for whatever reason, it states that <set> is not valid under <class> But the DTD says it is good.

Anyone see what I am missing here? I am using xml spy.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 11, 2006 11:53 am 
Regular
Regular

Joined: Tue Jan 03, 2006 9:52 am
Posts: 52
Location: Zurich
Hello
Please note, that you can either use entities or collections.
(See user manual of hibernate).

If you want to use the mapping that I proposed earlier,
it wood look like this:
Code:
<hibernate-mapping>
<class name="com.mb.purcell.User" table="USERS" >
  <id name="user_id" column="USER_ID" type="int">
    <generator class="identity"/>
  </id>
  <property name="username" column="username"   type="string" />
  <set name="passwords" table="PASSWORDS" >
    <key column="user_id"/>
   <composite-element class="Password">
      <property name="password" column="password" type="string"/>
  </composite-element>
  </set>
</class>
</hibernate-mapping>

I would suggest that you use class names in singular form and table names in plural (example: User/USERS).

There are other aproaches:
You probably do not even need a class Password.

Code:
<class name="User" table="USERS" >
  <id name="user_id" column="USER_ID" type="int">
    <generator class="identity"/>
  </id>
  <property name="username" column="username"  type="string" />
  <set name="passwords" table="PASSWORDS" >
    <key column="user_id"/>
    <element type="string" column="password"></element>

  </set>
</class>


Hope this helps!
Urs


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