-->
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.  [ 3 posts ] 
Author Message
 Post subject: cannot produce foreign key
PostPosted: Tue Feb 03, 2004 3:01 pm 
Beginner
Beginner

Joined: Fri Jan 23, 2004 10:26 am
Posts: 21
i have another newbie question. i tried to read parts of the documentation but i could not find the solution.

i have this two persistent classes,

Code:
public class PCard{
    private String id;
    private String serial;
    .....
}

public class PSession {
    private String id;
    private Date startTime;
    private Date endTime;
    private PCard card;
    ......
}


Both uses same id generation mechanism, something like that in their mapping file, for session:
Code:
        <id name="id" type="string" unsaved-value="null" >
            <column name="session_id" sql-type="char(32)" not-null="true"/>
            <generator class="uuid.hex"/>
        </id>


and Session includes this many-to-one relation line in the mapping file
Code:
        <many-to-one name="card"
          class="PCard"
          column="card_id" />


But when i wanted to use schema export for HSQLDB, it produces this tables for the objects, and gives a type error for friend key constraints because of the type difference. Question is, why the system makes the value of card_id in session table as VARCHAR? i know it is a simple mistake but i am confused..

Code:
create table cards (
   card_id char(32) not null,
   serial char(255) not null,
   primary key (card_id)
)

create table sessions (
   session_id char(32) not null,
   start_time date not null,
   end_time date not null,
   card_id VARCHAR(255),
   primary key (session_id)
)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 03, 2004 3:26 pm 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
I suspect it's guessing the sql-type and getting it wrong.

Try embedding a column tag in the many-to-one tag i.e.
Code:
    <many-to-one name="card"
          class="PCard">
              <column name="card_id" sql-type="char(32)" />
    </many-to-one>


I'm not sure if this will work - let me know
Justin


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 03, 2004 4:07 pm 
Beginner
Beginner

Joined: Fri Jan 23, 2004 10:26 am
Posts: 21
yes it is working. thanks.


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