-->
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.  [ 9 posts ] 
Author Message
 Post subject: Several questions from a new user
PostPosted: Fri Jun 16, 2006 4:02 pm 
Newbie

Joined: Fri Jun 16, 2006 3:41 pm
Posts: 18
Hi,
I'm trying to use Hibernate for an application and I'm in the process of learning it. I have some simple questions:
1. The documentation says "Hibernate can also access fields directly" so I didn't write any accessor methods. Now I get an exception "failed.org.hibernate.PropertyNotFoundException: Could not find a getter for ID ..." The fields are declared public. So how do I make it access fields directly?

2. All the classes that will go into the database are derrived from a superclass that implements some very important methods. Also some beans contain ArrayList<myotherBean> list as members. What do I have to worry about if I want inheritance? Do I need to overwrite equals() and hashCode()? I'm using generics for all my Lists so there's no confusion about the type...

3. The documentation has examples of using Sets. I need to use Lists since order of the data is important. Do I still use the <set name="*"> tag or is there a <list...> tag.

4. All of the classes should have "long ID" field, since they all descend from the same class how can I put that into the superclass (this is the logical thing to do)? I suspect this one's not possible with hibernate and it's not a huge deal.

Thanks for helping out a new user.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 16, 2006 4:35 pm 
Newbie

Joined: Thu Jun 15, 2006 2:15 pm
Posts: 15
Did you try the reverse enginering tool. It will give you a big head start on the mapping xml and POJO (plain old java objects)
It works with eclipse 3.1 or ANT. You can get it from hibernate.org The link is
http://sourceforge.net/project/showfile ... e_id=85666

You will also need to get the Hibernate in Action book and read it to have much success with Hibernate.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 16, 2006 4:58 pm 
Newbie

Joined: Fri Jun 16, 2006 3:41 pm
Posts: 18
I'm using netbeans, so that plugin probably won't work. I tried the plugin for netbeans 5.0 from http://nbxdoclet.sourceforge.net/ so far I didn't get it to work. But it's not a question of plugins...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 16, 2006 5:18 pm 
Newbie

Joined: Thu Jun 15, 2006 2:15 pm
Posts: 15
You can download eclipse at eclipse.org -- http://www.eclipse.org/downloads/
It's free and would be worth having if just to run the Hibernate reverse enginering tool
For as question #1 as far as I know you have to have getters and setters. You may be able to access the fields directly then but I wouldn't recommend it.

The other questions would probably be answered when you look at the generated xml and java objects from the generator.


Top
 Profile  
 
 Post subject: Re: Several questions from a new user
PostPosted: Fri Jun 16, 2006 5:42 pm 
Regular
Regular

Joined: Wed Feb 22, 2006 11:28 am
Posts: 65
Location: Santiago, Chile
I suggest you read all details of Hibernate Document Reference. Even said that, I will response you what you asked:

1. Hibernat throwed that exception, because in your "property" tag doesn´t specify the attribute "access = field"

2. It`s depending some cases. I suggest you to read Chapter 19 of Hibernate Reference Documentation. When you will work with same detached Objects in to two Sessions, you have to do it. Because Hibernate manage "identifer by id" and "JVM identifer" when you use one Session. When you use two Session (open 2 session) where your Object is cross to both, to avoid innecesary comparation, you can override. Reading more about this in Chapter 19.

3. That is specified in Chapter 19 too. Hibernate use "set" because semantically that sound more natural and logic. Like hibernate reference documentation said: Set is usually used. But it is good for "insert" or "delete" operations. How about "update" operation when you use "Set"? Hibernate will delete the row, then insert a new row. That is always bad thing to do... Because for the "Set" structure, Hibernate only specify the assocation with "key" but no "index" to indentify his allocation.

That is one difference with "List" that i explan follow:

so, Hibernate defined "List", that has best perfomance for all tree basic operacions , I mean "insert", "update" and "delete". Because, every element is assocated with a "key" and "index". The last one help you to identify the row that you want to do something.

4. Sr. Yes Sr. Yo can abstract the common methods or fields into your super class. Use the feature of Oriented Object Programing in JAVA.

Any questions is greatly appreciated.

Neketsu Shonen


Top
 Profile  
 
 Post subject: Re: Several questions from a new user
PostPosted: Mon Jun 19, 2006 6:11 pm 
Newbie

Joined: Tue Jun 13, 2006 12:35 pm
Posts: 1
[quote]thanks Neketsu

it really help me lot

can to tell from where i can find difference between different types of associction like map,list,bag etc .

Its confusing when u use which type


Govind Patwa[/img]


Top
 Profile  
 
 Post subject: Re: Several questions from a new user
PostPosted: Mon Jun 19, 2006 6:18 pm 
Regular
Regular

Joined: Wed Feb 22, 2006 11:28 am
Posts: 65
Location: Santiago, Chile
Hello Friend:

Read the Chpater 6 and 19 of Hibrenate Reference Documentation.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 21, 2006 5:19 pm 
Newbie

Joined: Fri Jun 16, 2006 3:41 pm
Posts: 18
I've read chapter 6 on collection mapping but still having some problems.
I have several <one-to-one> tags that don't work the way I expected. For example I have
<one-to-one name="geometry" class="myPackage.Geometry" foreign-key="INSTANCE_ID" cascade="all"/>
So I have an Instance class that has "Geometry geometry" as one of the variables. Both of these get entered into the database, however when I look in the database there's no foreign key created. I don't see any relationship that exists between geometry record and the Instance. I see data entered into both tables, it's just not related in any way that I can see.

The documentation says:
"Primary key associations don't need an extra table column; if two rows are related by the association then the two table rows share the same primary key value".
But I thought the foreign-key would cancel that? What I'm worried about is that I have this table that will have several one-to-one relationships and I don't know whether the generator will be able to generate a key that will satisfy all of them.

My sets and lists of values work and the foreign keys get created there so that's good.


Top
 Profile  
 
 Post subject: I think
PostPosted: Wed Jun 21, 2006 5:55 pm 
Regular
Regular

Joined: Wed Feb 22, 2006 11:28 am
Posts: 65
Location: Santiago, Chile
I think you can chance:

<one-to-one name="geometry" class="myPackage.Geometry" foreign-key="INSTANCE_ID" cascade="all"/>

to
<one-to-one class="myPackage.Geometry" name="geometry" property-ref="instance"/>

then, in your Geometry.hbm.xml, change your id tag like:

<id name="solSec" column="geometry_id">
<generator class="foreign">
<param name="property">instance</param>
</generator>
</id>
then add:

<one-to-one name="instance" constrained="true"/>


See all detail with <one-to-one> specification in hibernate reference.

Regards.


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