-->
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.  [ 10 posts ] 
Author Message
 Post subject: Annotation for dependent object
PostPosted: Mon Feb 14, 2005 6:43 am 
Newbie

Joined: Mon Feb 07, 2005 6:30 am
Posts: 8
Location: Paris, London
Hi there !

As an example, I would like to try a dependent object : a kind of String.
Let's call that object Text (it use a String internaly).

When I want to use a Text, I have to use :
Code:
@Basic()
@Dependent({
   @DependentAttribute(name="value", column = @Column(name="name") })
@Column(updatable = true, name = "name", nullable = true, length=50)
private bolide.type.Text name = null;


First question : what do you think about mixing @Column and @dependent ?
Is it correct ? I can't find other ways to specify the updatable status without @Column. On the other hand, why should I provide
Code:
@Column( name=)
since it is already provided inside the @dependent...

Second question, here is the code the the Text class :
Code:
@DependentObject(access = AccessType.FIELD)
public class Text {
    private String value;
[CUT]


Why should I use the @DependentObject ? I would love not to have to annotate that class. When I had used the Text attribute, it was mandatory to provide bolide.type.Text, so that sound like redundant information.

As I do not have to modify the String class itself it I woulld use it as a persistent attribute, I wonder why I should modify my own String class (here Text) ?

thanks !

_________________
Jean-Baptiste BRIAUD www.bolide.org


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 14, 2005 6:54 am 
Newbie

Joined: Mon Feb 07, 2005 6:30 am
Posts: 8
Location: Paris, London
I think I have an answer to my first question ;-)

Instead of using two annotatation, use only one like that :
Code:
@Basic()
@Dependent({
   @DependentAttribute(name="value", column = @Column(updatable = true, name = "name", nullable = true, length=50)
})


Correct ?

_________________
Jean-Baptiste BRIAUD www.bolide.org


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 14, 2005 7:13 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
For the 2nd question @Dependent is optional, you don't always have to override component columns.
So @DependentObject is mandatory.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 15, 2005 6:08 am 
Newbie

Joined: Mon Feb 07, 2005 6:30 am
Posts: 8
Location: Paris, London
In fact, that's I don't understand.
@Dependent is for the "business persistent object" while
@DependentObject is for the "new type object" like Text for a kind of String.

If I tell in my business object that an attribute is @Dependent on p.Text,
then, we should assume that p.Text is in the classpath and is persistent on FIELDS that are not transient for examples.

So, by default, it should be optional to modify the p.Text by adding annotations in it. I would like to be able to use p,Text from "outside" (I mean by otuside that I can't modify it).

Of course I talking of default, if one want to customize default and annotate p.Text, then it should be possible.

I would like to understant what lead the decision to make @DependentObject mandatory and @Depend optional ?

Also, as a discussion, what do you think of the reverse way o doing that : @Dependent would become mandatory and @DependentObject optional ?

How to you handle the types that would came from "outside" ?
In fact, we do not have to annotate String to be able to use it as an attribute in a business object ...

Thanks !

_________________
Jean-Baptiste BRIAUD www.bolide.org


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 15, 2005 6:55 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
A dependent object is not a type. It is a component in the Hibernate language.
@Dependent is a commodity for overriding
I know it looks more cool to use @Dependent, but don't be blind ;-)
We choose this way to avoid redundency. Like Strings I don't want to have to declare a component as persistent in the classes that use it.

The common usage is

Code:
@Entity
pulbic class Person {
  public Address getAddress();
}
@Entity
pulbic class Dog {
  public Address getOwnerAddress();
}

@DependentObject
public class Address {
  public String getAddress1()


Actually @Dependent has been added to work around a common issue in XDoclet where component columns were not overridable.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 15, 2005 9:33 am 
Newbie

Joined: Mon Feb 07, 2005 6:30 am
Posts: 8
Location: Paris, London
It is like all you said goes to the direction I talked about or I missed something. Your example is a perfect example of types or component.

Quote:
Like Strings I don't want to have to declare a component as persistent in the classes that use it.

I agree not to declare String persistent in clasees that use it, but I may use @Column for a String in the classe that use it. In both cases (with or without @Column) I will not have to change anything to the String class to be able to use is in another object.

So, the question is still there : why is it mandatory to modify Adresse component ?

You said
Quote:
I know it looks more cool to use @Dependent, but don't be blind ;-)

Nothing to do with cool or not, I would like to be able to use components from other project that I will not be able to change or that I don't want to change.
I said that because one solution could be inheritance :

Code:
public class Address {
  public String getAddress1()
}

@DependentObject
public class HibernateUsableAddress extends Address {
}


So, the question is what is the added value of the sub-class here ?
What does @DependentObject annotation change that could not be done without the annotation ?

Don't misunderstand my goal, I'm happy with Hibernate, I just want to understand how annotation works (including their limit if any).

_________________
Jean-Baptiste BRIAUD www.bolide.org


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 15, 2005 3:26 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
jbb wrote:
So, the question is still there : why is it mandatory to modify Adresse component ?

Once again, because a component is *not* a type.
A component can have associations (many to one or collections)... We're not talking about columns only.
A component is much more an entity than a type. So see @DependentObject much like @Entity.
If you need to reuse "sealed" classes, you'll be able to do it through the XML deployment descriptor

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 16, 2005 6:37 am 
Newbie

Joined: Mon Feb 07, 2005 6:30 am
Posts: 8
Location: Paris, London
Quote:
A component can have associations (many to one or collections)...

I've missed that point.

Unfortunatly, I would like to rely only on annotations.
Is there a solution that would help me to use sealed classes ?

What about having default option for annotation that would make use of component as type without having to modify it ?

For example, if you use
Code:
@Dependent({
   @DependentAttribute(name="value", column = @Column(name="name") })
private bolide.type.Text name = null;

then, bolide.type.Text would not have any annotation but no way to have assiciations inside Text also.
If you need a real component and not a type, then you would have to annotate on both side.

Thanks for your light !

_________________
Jean-Baptiste BRIAUD www.bolide.org


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 19, 2005 7:59 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You can't practically use annotations on sealed classes, consider xml configuration for them.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 19, 2005 8:22 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Note that allowing composite user type through annotations is on my road map.

_________________
Emmanuel


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