You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Terry Brick <te...@yahoo.com> on 2003/08/07 17:47:08 UTC

References Talking Smack

Hi,
Ok, here's the deal.  Everything had been working fine
up until the time I changed my Java beans (the objects
mapped in my OJB repository) to use wrapper classes
like Integer & Long instead of int & long.  Previously
I was mapping TINYINT (JDBC) to long (Java).  After
switching to Long, I had to change my JDBC types in
the repository.xml to BIGINT in order to get OJB up
and running again (I assume the fact that the "real"
JDBC type on the DB side is TINYINT should not
matter).  Anyway, after doing this I now have trouble
storing data that contains a reference.
First problem is that when doing broker.store(object),
my reference column is now trying to go into the db as
a null value.  Just before the store I can print out
the value, and that field is in fact NOT null!
System.out.println(object.getPrivilege_id());
The value is there.  However, the sql that's being
generated shows it as a null.
Ok, so searching through the OJB list archives, I saw
something that suggested I do a
broker.retrieveAllReferences(object) first, then
store.  However, when I do this, I get
"org.apache.ojb.broker.metadata.ClassDescriptor: Could
not find autoincrement attribute for class:
test.ojb.objects.Privilege"
Well that's good because Priviledge does NOT have an
autoincrement field, but I don't understand why it's
expecting one.

Here's the relevant XML
-----------------------------


<class-descriptor class="test.ojb.objects.User" 
table="user">
  <field-descriptor name="oid" column="USER_ID" 
jdbc-type="BIGINT" access="readonly" primarykey="true"
autoincrement="true"/>
  <field-descriptor name="username" column="USERNAME" 
jdbc-type="VARCHAR"/>
  <field-descriptor name="password" column="PASSWORD" 
jdbc-type="VARCHAR"/>
  <field-descriptor name="firstname"
column="FIRSTNAME" 
jdbc-type="VARCHAR"/>
  <field-descriptor name="lastname" column="LASTNAME" 
jdbc-type="VARCHAR"/>
  <field-descriptor name="privilege_id"
column="PRIVILEGE_ID" 
jdbc-type="BIGINT"/>
  <field-descriptor name="date_created"
column="DATE_CREATED" 
jdbc-type="TIMESTAMP" access="readonly"
conversion="org.apache.ojb.broker.accesslayer.conversions.JavaDate2SqlTimestampFieldConversion"/>
  <reference-descriptor name="privilege_id_ref" 
class-ref="test.ojb.objects.Privilege"
auto-retrieve="true">
     <foreignkey field-ref="privilege_id"/>
  </reference-descriptor>
</class-descriptor>




<class-descriptor class="test.ojb.objects.Privilege" 
table="security">
  <field-descriptor name="oid" column="PRIVILEGE_ID" 
jdbc-type="BIGINT" primarykey="true" />
  <field-descriptor name="name" column="NAME" 
jdbc-type="VARCHAR"/>
   <collection-descriptor name="users" 
element-class-ref="test.ojb.objects.User"
auto-retrieve="false" auto-update="false" 
auto-delete="false">
     <inverse-foreignkey field-ref="privilege_id"/>
  </collection-descriptor>
</class-descriptor>

--------------------------
The other interesting thing is that
retrieveAllReferences() seems to work fine if the
target object already exists in the database (the
primary key property is not null)... for example, when
doing an update instead of an insert.  I'm using OBJ
1.0RC4.

What am I doing wrong??
Thank you

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org