Re: [ojb-users] Type Mismatch problem
Brought to you by:
thma
From: Thomas M. <tho...@ho...> - 2002-05-12 20:25:33
|
Hi Jason, There is a bug in your repository. (see my remarks below) Jason McKerr wrote: > Sorry for the long message. If you don't feel like reading all this > crap, don't worry about it. Could use some help though. > > > I'm new to ORM stuff. > I set up a sample DB and classes. Everything works OK until I try > to use auto-retrieve for related columns in a related table. > As soon as I turn <auto.retrieve> to true, everything blows up. > > I've got two tables, DB_USERS and DB_USERS_ROLES > > The primary key in DB_USERS is username, which relates to the > username column in the DB_USERS_ROLES table. > > here's my repository.xml for these. I have defined the references > pretty much the same as in the Artikel and Category examples in the > distro. > > ------------------------------------------------------------------ > <!-- Definitions for org.nacse.data.UserRole --> > <ClassDescriptor id="1101"> > <class.name>org.nacse.data.user.UserRole</class.name> > <table.name>DB_USERS_ROLES</table.name> > <FieldDescriptor id="1"> > <field.name>userName</field.name> > <column.name>USERNAME</column.name> > <jdbc_type>VARCHAR</jdbc_type> > <PrimaryKey>true</PrimaryKey> > </FieldDescriptor> > <FieldDescriptor id="2"> > <field.name>roleName</field.name> > <column.name>ROLENAME</column.name> > <jdbc_type>VARCHAR</jdbc_type> > <PrimaryKey>true</PrimaryKey> > </FieldDescriptor> > <ReferenceDescriptor id="1"> > <rdfield.name>userName</rdfield.name> > <referenced.class>org.nacse.data.user.User</referenced.class> > <fk_descriptor_ids>1</fk_descriptor_ids> > <auto.retrieve>true</auto.retrieve> > <auto.update>false</auto.update> > <auto.delete>false</auto.delete> > </ReferenceDescriptor> This ReferenceDescriptor is buggy ! It says: there is an attribute userName of type org.nacse.data.user.User. But in FieldDescriptor 1 you say userName is a String (or char[]). Is there a reference-attribute of type User in class UserRole? If so use its name. If not, just drop this descriptor. If there is no navigability from UserRole to User, you won't need a ReferenceDescriptor. HTH, Thomas > </ClassDescriptor> > <!-- Definitions for org.nacse.data.User --> > <ClassDescriptor id="1102"> > <class.name>org.nacse.data.user.User</class.name> > <table.name>DB_USERS</table.name> > <FieldDescriptor id="1"> > <field.name>userName</field.name> > <column.name>USERNAME</column.name> > <jdbc_type>VARCHAR</jdbc_type> > <PrimaryKey>true</PrimaryKey> > </FieldDescriptor> > <FieldDescriptor id="2"> > <field.name>password</field.name> > <column.name>PASSWORD</column.name> > <jdbc_type>VARCHAR</jdbc_type> > </FieldDescriptor> > <FieldDescriptor id="3"> > <field.name>firstName</field.name> > <column.name>FIRSTNAME</column.name> > <jdbc_type>VARCHAR</jdbc_type> > </FieldDescriptor> > <FieldDescriptor id="4"> > <field.name>lastName</field.name> > <column.name>LASTNAME</column.name> > <jdbc_type>VARCHAR</jdbc_type> > </FieldDescriptor> > <FieldDescriptor id="5"> > <field.name>organization</field.name> > <column.name>ORGANIZATION</column.name> > <jdbc_type>VARCHAR</jdbc_type> > </FieldDescriptor> > <CollectionDescriptor id="1"> > <cdfield.name>roles</cdfield.name> > <items.class>org.nacse.data.user.UserRole</items.class> > <inverse_fk_descriptor_ids>1</inverse_fk_descriptor_ids> > <auto.retrieve>true</auto.retrieve> > <auto.update>true</auto.update> > <auto.delete>false</auto.delete> > <orderby sort="DESC">rolename</orderby> > </CollectionDescriptor> > </ClassDescriptor> > ----------------------------------------------------------------- > > Then I have my User class > > > ----------------------------------------------------------------- > public class User extends DataObjectBroker implements Serializable { > > static Logger log = Logger.getLogger(User.class); > > private String userName; > private String password; > private String firstName; > private String lastName; > private String organization; > private List roles; > > public User() { > } > public User(String inUserName, > String inPassword, > String inFirstName, > String inLastName, > String inOrganization) { > this.userName = inUserName; > this.password = inPassword; > this.firstName = inFirstName; > this.lastName = inLastName; > this.organization = inOrganization; > } > public synchronized void add(UserRole ur) { > if (roles == null) { > roles = new Vector(); > } > roles.add(ur); > } > public String getUserName() { > return userName; > } > public void setUserName(String inUserName) { > userName = inUserName; > } > public String getPassword() { > return password; > } > public void setPassword(String inPassword) { > password = inPassword; > } > public String getFirstName() { > return firstName; > } > public void setFirstName(String inFirstName) { > firstName = inFirstName; > } > public String getLastName() { > return lastName; > } > public void setLastName(String inLastName) { > lastName = inLastName; > } > public String getOrganization() { > return lastName; > } > public void setOrganization(String inOrganization) { > organization = inOrganization; > } > public List getRoles() { > return roles; > } > public void setRoles(List inRoles) { > roles = inRoles; > } > > public List listAllUsers() { > Query query = new QueryByCriteria(User.class, null); > try { > List allUsers = (List)broker.getCollectionByQuery(query); > return allUsers; > } > catch (Exception e) { > log.error("Exception in listAllRoles(): " + e); > e.printStackTrace(); > } > return null; > } > } > ------------------------------------------------------------------ > > When I run the listAllUsers() method without autoretrieve, ok. > If I turn it on, then I get the following. This appears to be > introspection of some kind, but I'm not sure what is going on. > Why is the system getting User, when it wants String? > Is this happening in the UserRole class? or in the User class? > How do I figure that out? > > [DEFAULT] ERROR: field: userName, type: class java.lang.String > [DEFAULT] ERROR: value: org.nacse.data.user.User@347124, type: class > org.nacse.data.user.User > [ojb.broker.singlevm.PersistenceBrokerImpl] ERROR: expected type: class > java.lang.String > [ojb.broker.singlevm.PersistenceBrokerImpl] DEBUG: getObjectByIdentity > org.nacse.data.user.User{mckerrj} > [ojb.broker.singlevm.PersistenceBrokerImpl] ERROR: actual type: class > org.nacse.data.user.User > [ojb.broker.singlevm.PersistenceBrokerImpl] ERROR: field type mismatch > > > > Any help would be greatly appreciated. Thanks! > > -Jason > > > > > > > > > > > > > > > > > > > _______________________________________________________________ > > Have big pipes? SourceForge.net is looking for download mirrors. We supply > the hardware. You get the recognition. Email Us: ban...@so... > _______________________________________________ > Objectbridge-users mailing list > Obj...@li... > https://lists.sourceforge.net/lists/listinfo/objectbridge-users > > > > |