-->
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: XDoclet - Questions
PostPosted: Sat Dec 11, 2004 9:42 am 
Newbie

Joined: Tue Nov 30, 2004 5:07 am
Posts: 14
Hi,

I'm new to this whole Hibernate-thing and also in using XDoclet. So I've some questions:

I want to use a foreign key in a column. I assume that I have to use a many-to-one-association to do so. For example:

Code:
/**
* @hibernate.many-to-one column="FOOID" class="FooClass"
* @return Returns the fooID.
*/
public String getFooID() {
      return fooID;
}


So in column FOOID in the current table will be a foreign key to the table that is defined in class "FooClass" (Do I have to mention the package for FooClass even if all persistent classes are in com.myPackage.pojo?). Because no column for class FooClass was defined, the id-column (primary key) is used. Right?

The next step is to define 2 columns as unique. If I get it right, that means that the combination of columnA=4 and columnB=6 can only appears once in a table.
All columns that should be unique with FOOID must have the following line?
Code:
* @hibernate.column unique-key="unique"

For example:

Code:
/**
* @hibernate.many-to-one column="FOOID" class="FooClass"
* @hibernate.column unique-key="unique"
* @return Returns the fooID.
*/
public String getFooID() {
      return fooID;
}

/**
* @hibernate.property column="NAME" length="30" not-null="true"
* @hibernate.column unique-key="unique"
* @return Returns the name.
*/
public String getName() {
      return name;
}



Thanks
smo


Top
 Profile  
 
 Post subject: Re: XDoclet - Questions
PostPosted: Sat Dec 11, 2004 10:06 am 
Senior
Senior

Joined: Wed Aug 27, 2003 4:08 am
Posts: 178
Location: Wiesbaden, Germany
Smoeller00 wrote:
Hi,

I'm new to this whole Hibernate-thing and also in using XDoclet. So I've some questions:

I want to use a foreign key in a column. I assume that I have to use a many-to-one-association to do so. For example:

Code:
/**
* @hibernate.many-to-one column="FOOID" class="FooClass"
* @return Returns the fooID.
*/
public String getFooID() {
      return fooID;
}




If you use many-to-one, you'll have to have return type of class, not his ID, in this case you do not have to specify class at all ( taken from return type )


Smoeller00 wrote:
The next step is to define 2 columns as unique. If I get it right, that means that the combination of columnA=4 and columnB=6 can only appears once in a table.
All columns that should be unique with FOOID must have the following line?
Code:
* @hibernate.column unique-key="unique"

For example:

Code:
/**
* @hibernate.many-to-one column="FOOID" class="FooClass"
* @hibernate.column unique-key="unique"
* @return Returns the fooID.
*/
public String getFooID() {
      return fooID;
}

[/quote]
@hibernate.many-to-one column="FOOID" unique="true"
[quote]
/**
* @hibernate.property column="NAME" length="30" not-null="true"
* @hibernate.column unique-key="unique"
* @return Returns the name.
*/
public String getName() {
      return name;
}


@hibernate.property column="name" length="30" not.null="true" unique="true"

I'm referring to xdoclet-2 plugin though.
Look here for docs about hibernate tags:
http://xdoclet.codehaus.org/HibernateTags

_________________
Got new hibernate xdoclet plugin? http://www.sourceforge.net/projects/xdoclet-plugins/
... Momentan auf der Suche nach neuen Projekt ode Festanstellung....


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 11, 2004 11:54 am 
Newbie

Joined: Tue Nov 30, 2004 5:07 am
Posts: 14
Thanks for answering quickly!
Ouuh, seems that I misunterstood this important part of hibernate.

So, you declare a column in your table that should care about the foreign key (e.g. MATE_ID from http://www.hibernate.org/hib_docs/reference/en/html/persistent-classes.html#persistent-classes-xdoclet)
When you later use the method getMate(), Hibernate is looking what kind of return type is expected. In this case this is "Cat". In class "Cat" is defined that the dedicated table is called "CATS". Hibernate is looking for the key (from MATE_ID) in table "CATS", creates a new Cat-object with the information found and returns it to you after you invoked getMate().
Is that the way how it's working?


About "unique":
I think, that
Code:
@hibernate.property column="name" length="30" not.null="true" unique="true"
would only make the current column unique. But I want the combination of two or more columns columns affected.

smo


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 11, 2004 12:07 pm 
Senior
Senior

Joined: Wed Aug 27, 2003 4:08 am
Posts: 178
Location: Wiesbaden, Germany
Smoeller00 wrote:
Thanks for answering quickly!
Ouuh, seems that I misunterstood this important part of hibernate.

So, you declare a column in your table that should care about the foreign key (e.g. MATE_ID from http://www.hibernate.org/hib_docs/reference/en/html/persistent-classes.html#persistent-classes-xdoclet)
When you later use the method getMate(), Hibernate is looking what kind of return type is expected. In this case this is "Cat". In class "Cat" is defined that the dedicated table is called "CATS". Hibernate is looking for the key (from MATE_ID) in table "CATS", creates a new Cat-object with the information found and returns it to you after you invoked getMate().
Is that the way how it's working?

Yes.
Quote:

About "unique":
I think, that
Code:
@hibernate.property column="name" length="30" not.null="true" unique="true"
would only make the current column unique. But I want the combination of two or more columns columns affected.

smo


well, check with hibenate docs... I'm not sure how to do this. But you will occasionally get this semantics implicitely with relations.

_________________
Got new hibernate xdoclet plugin? http://www.sourceforge.net/projects/xdoclet-plugins/
... Momentan auf der Suche nach neuen Projekt ode Festanstellung....


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.