You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by ngong <ma...@august.de> on 2012/01/26 01:00:30 UTC

attribute is missing

Something I missed with the modeler.

I created a model with two tables in modeler: MASTER and DETAIL.

MASTER has ID as the PK and NAME as an attribute.
DETAIL has a two column PK: MASTER and COUNT, and a NAME attribute as well.
The MASTER column is also a relationship to the MASTER TABLE.

When I create object entities, the COUNT field is missing at all.

Here is the the regarding xml:

<?xml version="1.0" encoding="utf-8"?>
<data-map xmlns="http://cayenne.apache.org/schema/3.0/modelMap"
	 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	 xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap
http://cayenne.apache.org/schema/3.0/modelMap.xsd"
	 project-version="6">
	<property name="defaultPackage" value="eu.ngong.test.cayenne.persistent"/>
	<db-entity name="DETAIL">
		<db-attribute name="COUNT" type="INTEGER" isPrimaryKey="true"
isMandatory="true"/>
		<db-attribute name="MASTER" type="INTEGER" isPrimaryKey="true"
isMandatory="true"/>
		<db-attribute name="NAME" type="VARCHAR" length="256"/>
	</db-entity>
	<db-entity name="MASTER">
		<db-attribute name="ID" type="INTEGER" isPrimaryKey="true"
isMandatory="true"/>
		<db-attribute name="NAME" type="VARCHAR" length="256"/>
	</db-entity>
	<obj-entity name="Detail"
className="eu.ngong.test.cayenne.persistent.Detail" dbEntityName="DETAIL">
		<obj-attribute name="name" type="java.lang.String"
db-attribute-path="NAME"/>
	</obj-entity>
	<obj-entity name="Master"
className="eu.ngong.test.cayenne.persistent.Master" dbEntityName="MASTER">
		<obj-attribute name="name" type="java.lang.String"
db-attribute-path="NAME"/>
	</obj-entity>
	<db-relationship name="toMaster" source="DETAIL" target="MASTER"
toMany="false">
		<db-attribute-pair source="MASTER" target="ID"/>
	</db-relationship>
	<db-relationship name="toDetail" source="MASTER" target="DETAIL"
toDependentPK="true" toMany="true">
		<db-attribute-pair source="ID" target="MASTER"/>
	</db-relationship>
	<obj-relationship name="toDetail" source="Master" target="Detail"
deleteRule="Deny" db-relationship-path="toDetail"/>
</data-map>

Any idea for me why obj-entity Deail is missing the count attribute?

--
View this message in context: http://cayenne.195.n3.nabble.com/attribute-is-missing-tp3689400p3689400.html
Sent from the Cayenne - User mailing list archive at Nabble.com.

Re: attribute is missing

Posted by ngong <ma...@august.de>.
Sounds good to me, Michael, thank you for your answer. No problem to cope
with this optimization. And I agree automatic PKs are to be favored.
However, sometimes  you got to cope with existing schemas.

--
View this message in context: http://cayenne.195.n3.nabble.com/attribute-is-missing-tp3689400p3697603.html
Sent from the Cayenne - User mailing list archive at Nabble.com.

Re: attribute is missing

Posted by Michael Gentry <mg...@masslight.net>.
Hi there,

By default, Cayenne assumes that keys (primary and foreign) are
generated keys and not natural data, therefore columns that are keys
do not automatically get added to the Java object, although you can
add them in by hand.

There was some discussion in the past of maybe having an option to
automatically map keys in the modeler, but this hasn't been a high
priority item so far.

Thanks,

mrg


On Thu, Jan 26, 2012 at 3:14 PM, ngong <ma...@august.de> wrote:
> Thank you and ok, Ari, COUNT is a bad name, fully accepted, have not thought
> about it.
>
> The other subject: If I have a schema by which I can create a database: Why
> is the ORM mechanism Cayenne able to reflect that in object entiies only by
> manual afterwork? (I added count to the Detail class in the modeler and it
> seems to work for me.) I would assume that all columns contained in the
> schema can be accessible from the programming language after generating the
> classes to it. But "COUNT" is not accessible after the generation of the
> classes.
>
> How do I have to "add to the modeler" by changing the schema in order to get
> equivalent classes by synchronization that I do not have to correct
> manually?
>
> I hope you dont mind. This all is no problem, just to make me understand
> Cayenne for my goal, conquering eHour database.
>
> --
> View this message in context: http://cayenne.195.n3.nabble.com/attribute-is-missing-tp3689400p3691479.html
> Sent from the Cayenne - User mailing list archive at Nabble.com.

Re: attribute is missing

Posted by ngong <ma...@august.de>.
Thank you and ok, Ari, COUNT is a bad name, fully accepted, have not thought
about it.

The other subject: If I have a schema by which I can create a database: Why
is the ORM mechanism Cayenne able to reflect that in object entiies only by
manual afterwork? (I added count to the Detail class in the modeler and it
seems to work for me.) I would assume that all columns contained in the
schema can be accessible from the programming language after generating the
classes to it. But "COUNT" is not accessible after the generation of the
classes.

How do I have to "add to the modeler" by changing the schema in order to get
equivalent classes by synchronization that I do not have to correct
manually?

I hope you dont mind. This all is no problem, just to make me understand
Cayenne for my goal, conquering eHour database. 

--
View this message in context: http://cayenne.195.n3.nabble.com/attribute-is-missing-tp3689400p3691479.html
Sent from the Cayenne - User mailing list archive at Nabble.com.

Re: attribute is missing

Posted by Aristedes Maniatis <ar...@maniatis.org>.
On 26/01/12 11:00 AM, ngong wrote:
> Something I missed with the modeler.
>
> I created a model with two tables in modeler: MASTER and DETAIL.
>
> MASTER has ID as the PK and NAME as an attribute.
> DETAIL has a two column PK: MASTER and COUNT, and a NAME attribute as well.
> The MASTER column is also a relationship to the MASTER TABLE.
>
> When I create object entities, the COUNT field is missing at all.
>
> Here is the the regarding xml:
>
> <?xml version="1.0" encoding="utf-8"?>
> <data-map xmlns="http://cayenne.apache.org/schema/3.0/modelMap"
> 	 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> 	 xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap
> http://cayenne.apache.org/schema/3.0/modelMap.xsd"
> 	 project-version="6">
> 	<property name="defaultPackage" value="eu.ngong.test.cayenne.persistent"/>
> 	<db-entity name="DETAIL">
> 		<db-attribute name="COUNT" type="INTEGER" isPrimaryKey="true"
> isMandatory="true"/>
> 		<db-attribute name="MASTER" type="INTEGER" isPrimaryKey="true"
> isMandatory="true"/>
> 		<db-attribute name="NAME" type="VARCHAR" length="256"/>
> 	</db-entity>
> 	<db-entity name="MASTER">
> 		<db-attribute name="ID" type="INTEGER" isPrimaryKey="true"
> isMandatory="true"/>
> 		<db-attribute name="NAME" type="VARCHAR" length="256"/>
> 	</db-entity>
> 	<obj-entity name="Detail"
> className="eu.ngong.test.cayenne.persistent.Detail" dbEntityName="DETAIL">
> 		<obj-attribute name="name" type="java.lang.String"
> db-attribute-path="NAME"/>
> 	</obj-entity>
> 	<obj-entity name="Master"
> className="eu.ngong.test.cayenne.persistent.Master" dbEntityName="MASTER">
> 		<obj-attribute name="name" type="java.lang.String"
> db-attribute-path="NAME"/>
> 	</obj-entity>
> 	<db-relationship name="toMaster" source="DETAIL" target="MASTER"
> toMany="false">
> 		<db-attribute-pair source="MASTER" target="ID"/>
> 	</db-relationship>
> 	<db-relationship name="toDetail" source="MASTER" target="DETAIL"
> toDependentPK="true" toMany="true">
> 		<db-attribute-pair source="ID" target="MASTER"/>
> 	</db-relationship>
> 	<obj-relationship name="toDetail" source="Master" target="Detail"
> deleteRule="Deny" db-relationship-path="toDetail"/>
> </data-map>
>
> Any idea for me why obj-entity Deail is missing the count attribute?


You didn't add it in the modeler.

Also, "count" is a bad dbAttribute name. It may work since Cayenne will quote identifiers, but on the whole I think it is a bad idea to pick reserved SQL keywords.

Ari


-- 
-------------------------->
Aristedes Maniatis
GPG fingerprint CBFB 84B4 738D 4E87 5E5C  5EFA EF6A 7D2E 3E49 102A