You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by cay dabbler <xs...@ouvip.com> on 2006/07/27 10:04:52 UTC

Missing DbAttribute

1. I have two classes Foo1 and Foo2; 
2. Foo1 is a super class of Foo2 

Under Foo2 -> Attribute, the DbAttribute is blank for all the  Foo2 own
attributes.

Yes, I have done some edited and it was ok until I reopen the cayenne.xml
file. I am writting my own singleclass.vm template, and the absence of Foo2
DbAttributes mean that I cannot access the dbAttribute methods such as
MaxLength(), Name() etc. to do the following:

@javax.persistence.Column(name = "${dbAttr.Name}",
length="${dbAttr.MaxLength}" #if($dbAttr.isMandatory()), nullable = false
#else , nullable = true #end)
    public ${attr.Type} get${stringUtils.capitalized($attr.Name)}() {
        return this.${attr.Name};
    }  

I suppose, this is not what cayenne is meant for, but eh, that's what
invention is all about.  

What must I do to force a display of all Foo2 DbAtttibutes ? 


-- 
View this message in context: http://www.nabble.com/Missing-DbAttribute-tf2008259.html#a5516956
Sent from the Cayenne - User forum at Nabble.com.


Re: Missing DbAttribute

Posted by Mike Kienenberger <mk...@gmail.com>.
On 7/27/06, cay dabbler <xs...@ouvip.com> wrote:
> >Ie,    Foo2.getFoo1Attribute is generated as
> >getFoo1().getFoo1Attribute() underneath.
>
> Thanks for your reply. I can manage the small incovenience of
> (re)re-engineering my schema and editing the objects- every time I reload
> Cayenne. I am, however, too lazy for vertical inheritance: This is how I did
> my inheritance: excerpt from my *.vm:

Yes, I wasn't trying to tell you that you should do inheritance
differently.  I was stating that I'm doing it differently and can't
really help much.  I'm not completely certain what you need to do
differently than is being done in your generated classes, but there's
probably a way to do it without requiring you to manually edit your
generated classes.


> >It's not that straight-forward.   Every ObjAttribute has a
> >DbAttribute, but every DBAttribute can have zero or one or probably
> >even many matching ObjAttributes.
>
> Rather odd, are you saying that a dbAttribute is mapped to zero or more
> objAttributes, whereas an objAttribute is mapped to one dbAttribute?

Yes.   It's not really that odd.   It's simply saying that every java
property maps to exactly one database field.    It's also saying that
a particular database field may map to no java property, exactly one
java property (99.999% of the time), or multiple java properties (I've
never had a use case for this so far, but there's no reason why it
couldn't happen, I suppose).

Re: Missing DbAttribute

Posted by cay dabbler <xs...@ouvip.com>.
>Ie,    Foo2.getFoo1Attribute is generated as 
>getFoo1().getFoo1Attribute() underneath.


Mike, 
Thanks for your reply. I can manage the small incovenience of
(re)re-engineering my schema and editing the objects- every time I reload
Cayenne. I am, however, too lazy for vertical inheritance: This is how I did
my inheritance: excerpt from my *.vm:

#set( $cdo = "CayenneDataObject")  // DON'T NEED THIS CLASS IN EJB
@javax.persistence.Entity
@javax.persistence.Table(name = "${entityUtils.subClassName}",
schema="${objEntity.DbEntity.Schema}" )

#if(${entityUtils.subClassName} && ${entityUtils.subClassName} != $cdo)
@javax.persistence.Inheritance(strategy=javax.persistence.InheritanceType.JOINED)
@javax.persistence.DiscriminatorValue("${entityUtils.subClassName}")
@javax.persistence.DiscriminatorColumn(name="${stringUtils.capitalized(${entityUtils.subClassName})_TYPE",
discriminatorType=@javax.persistence.DiscriminatorType.STRING)

#elseif(${entityUtils.baseClassName} && ${entityUtils.baseClassName} !=
$cdo)
@javax.persistence.Inheritance(strategy=javax.persistence.InheritanceType.JOINED)
@javax.persistence.DiscriminatorValue("${entityUtils.subClassName}")
@javax.persistence.PrimaryKeyJoinColumn(name="ID",
referencedColumnName="ID")
#end

public class ${entityUtils.subClassName}EJB #if(${entityUtils.baseClassName}
&& ${entityUtils.baseClassName} != $cdo) extends
${entityUtils.baseClassName}EJB #end  implements java.io.Serializable{
}

>It's not that straight-forward.   Every ObjAttribute has a 
>DbAttribute, but every DBAttribute can have zero or one or probably 
>even many matching ObjAttributes.

Rather odd, are you saying that a dbAttribute is mapped to zero or more
objAttributes, whereas an objAttribute is mapped to one dbAttribute?



-- 
View this message in context: http://www.nabble.com/Missing-DbAttribute-tf2008259.html#a5527985
Sent from the Cayenne - User forum at Nabble.com.


Re: Missing DbAttribute

Posted by Mike Kienenberger <mk...@gmail.com>.
On 7/27/06, cay dabbler <xs...@ouvip.com> wrote:
> Thanks for your quick reply. I am frustrated with a whole host of
> velocity2ejb generators.  I find Cayenne more useful for my purpose even
> though it does not make grand claims - as the other generators do.

It's all velocity underneath -- it's just a matter of how you put
things into the context.


> I am using Cayenne to generate EJB 3.0, JSF and Webservice – true, and a
> whole load of other stuff. I am particularly attracted to Cayenne
> inheritance facilities.

Cool.  I'm also using Cayenne to generate JSF-related information
(converters, selectItemProviders, some DAO objects and matching
faces-config files, and facelet pages for each DataObject.

I'm using vertical inheritance which isn't directly supported by
Cayenne, but which can be simulated using custom templating and a
delegation pattern.


> I do want to map DbAttributes to the corresponding ObjAttributes, but I
> don't know what I am doing wrong.
>
> Scenario:
> 1 In my database schema
> a)  I have  CONSTRAINT FK_FOO1_TABLE_1 FOREIGN KEY(ID) REFERENCES
> FOO2_TABLE(D));
>
> 2. In Cayenne
> a) I make Foo1 the superclass of Foo2
> b). FOO1_TABLE has a row defined:  NAME=toFoo2Table , TARGET=FOO2_TABLE, To
> Dep PK= true;
> Problem:
> I don't know why (2b) is necessary. Anyway, I deleted the row and that's
> when my problem started. If I don't remove it, I get something like:
>
> Class Foo1{
> private  Foo2  toFoo2; // UGLY, DON'T WANT THIS
> }
> Class Foo2 extends Foo1{
> }

If I understand correctly, this db attribute relationship simply says
that the primary key for Foo1 will always be the same as Foo2 (the
foo1 primary key is dependent on foo2).   This is probably true in
your case.

Can't really help on the inheritance part.   With vertical
inheritance, foo2 doesn't actually extend foo1.   Instead, delegating
methods are made in foo2 for each foo1 attribute.

Ie,    Foo2.getFoo1Attribute is generated as
getFoo1().getFoo1Attribute() underneath.


> One more thing:
> In the Cayenne API doc, The ObjAttribute class has:
> DbAttribute getDbAttribute();
>
> It would be nice to have in the DBAttribute: class
> ObjAttribute  getObjAttribute();

It's not that straight-forward.   Every ObjAttribute has a
DbAttribute, but every DBAttribute can have zero or one or probably
even many matching ObjAttributes.

Re: Missing DbAttribute

Posted by cay dabbler <xs...@ouvip.com>.
Andrus, 
Thanks for your quick reply. I am frustrated with a whole host of
velocity2ejb generators.  I find Cayenne more useful for my purpose even
though it does not make grand claims - as the other generators do. 

I am using Cayenne to generate EJB 3.0, JSF and Webservice – true, and a
whole load of other stuff. I am particularly attracted to Cayenne
inheritance facilities. 

I do want to map DbAttributes to the corresponding ObjAttributes, but I
don't know what I am doing wrong. 

Scenario:
1 In my database schema
a)  I have  CONSTRAINT FK_FOO1_TABLE_1 FOREIGN KEY(ID) REFERENCES
FOO2_TABLE(D));

2. In Cayenne
a) I make Foo1 the superclass of Foo2 
b). FOO1_TABLE has a row defined:  NAME=toFoo2Table , TARGET=FOO2_TABLE, To
Dep PK= true;

Problem:
I don't know why (2b) is necessary. Anyway, I deleted the row and that's
when my problem started. If I don't remove it, I get something like:

Class Foo1{
private  Foo2  toFoo2; // UGLY, DON'T WANT THIS
}
Class Foo2 extends Foo1{
}

One more thing:
In the Cayenne API doc, The ObjAttribute class has: 
DbAttribute getDbAttribute();

It would be nice to have in the DBAttribute: class 
ObjAttribute  getObjAttribute();

Phew!

-- 
View this message in context: http://www.nabble.com/Missing-DbAttribute-tf2008259.html#a5526020
Sent from the Cayenne - User forum at Nabble.com.


Re: Missing DbAttribute

Posted by Andrus Adamchik <an...@objectstyle.org>.
BTW, if you were going to achieve something akin to JPA defaults  
functionality, this may be coming soon. This sort of works already in  
the JPA module which is external to the rest of the runtime. We might  
as well push it down the stack, making the defaults native to the  
rest of Cayenne. Just thinking out loud...

Andrus


On Jul 27, 2006, at 9:39 AM, Andrus Adamchik wrote:

> Hi,
>
>> Under Foo2 -> Attribute, the DbAttribute is blank for all the   
>> Foo2 own
>> attributes.
>
> ...
>
>> I am writting my own singleclass.vm template, and the absence of Foo2
>> DbAttributes mean that I cannot access the dbAttribute methods  
>> such as
>> MaxLength(), Name() etc.
>
> I am a bit confused - you do not want to map DbAttributes for  
> certain object attributes, but then later you want to access them?  
> Could you explain?
>
>> @javax.persistence.Column(name = "${dbAttr.Name}",
>
> Woa! you are building some JPA annotations. Care to elaborate how  
> you were planning to do with those? :-)
>
> Andrus
>
>
>
> On Jul 27, 2006, at 4:04 AM, cay dabbler wrote:
>
>>
>> 1. I have two classes Foo1 and Foo2;
>> 2. Foo1 is a super class of Foo2
>>
>> Under Foo2 -> Attribute, the DbAttribute is blank for all the   
>> Foo2 own
>> attributes.
>>
>> Yes, I have done some edited and it was ok until I reopen the  
>> cayenne.xml
>> file. I am writting my own singleclass.vm template, and the  
>> absence of Foo2
>> DbAttributes mean that I cannot access the dbAttribute methods  
>> such as
>> MaxLength(), Name() etc. to do the following:
>>
>> @javax.persistence.Column(name = "${dbAttr.Name}",
>> length="${dbAttr.MaxLength}" #if($dbAttr.isMandatory()), nullable  
>> = false
>> #else , nullable = true #end)
>>     public ${attr.Type} get${stringUtils.capitalized($attr.Name)}() {
>>         return this.${attr.Name};
>>     }
>>
>> I suppose, this is not what cayenne is meant for, but eh, that's what
>> invention is all about.
>>
>> What must I do to force a display of all Foo2 DbAtttibutes ?
>>
>>
>> -- 
>> View this message in context: http://www.nabble.com/Missing- 
>> DbAttribute-tf2008259.html#a5516956
>> Sent from the Cayenne - User forum at Nabble.com.
>>
>>
>
>


Re: Missing DbAttribute

Posted by Andrus Adamchik <an...@objectstyle.org>.
Hi,

> Under Foo2 -> Attribute, the DbAttribute is blank for all the  Foo2  
> own
> attributes.

...

> I am writting my own singleclass.vm template, and the absence of Foo2
> DbAttributes mean that I cannot access the dbAttribute methods such as
> MaxLength(), Name() etc.

I am a bit confused - you do not want to map DbAttributes for certain  
object attributes, but then later you want to access them? Could you  
explain?

> @javax.persistence.Column(name = "${dbAttr.Name}",

Woa! you are building some JPA annotations. Care to elaborate how you  
were planning to do with those? :-)

Andrus



On Jul 27, 2006, at 4:04 AM, cay dabbler wrote:

>
> 1. I have two classes Foo1 and Foo2;
> 2. Foo1 is a super class of Foo2
>
> Under Foo2 -> Attribute, the DbAttribute is blank for all the  Foo2  
> own
> attributes.
>
> Yes, I have done some edited and it was ok until I reopen the  
> cayenne.xml
> file. I am writting my own singleclass.vm template, and the absence  
> of Foo2
> DbAttributes mean that I cannot access the dbAttribute methods such as
> MaxLength(), Name() etc. to do the following:
>
> @javax.persistence.Column(name = "${dbAttr.Name}",
> length="${dbAttr.MaxLength}" #if($dbAttr.isMandatory()), nullable =  
> false
> #else , nullable = true #end)
>     public ${attr.Type} get${stringUtils.capitalized($attr.Name)}() {
>         return this.${attr.Name};
>     }
>
> I suppose, this is not what cayenne is meant for, but eh, that's what
> invention is all about.
>
> What must I do to force a display of all Foo2 DbAtttibutes ?
>
>
> -- 
> View this message in context: http://www.nabble.com/Missing- 
> DbAttribute-tf2008259.html#a5516956
> Sent from the Cayenne - User forum at Nabble.com.
>
>