You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Marcin Skladaniec <ma...@ish.com.au> on 2007/04/17 11:11:37 UTC

vertical inheritance

Hi

In our project we have tried using inheritance, this is the  
simplification of the map we are using:

<db-entity name="AbstractNode">
		<db-attribute name="id" type="INTEGER" isPrimaryKey="true"  
isMandatory="true"/>
		<db-attribute name="isDeleted" type="BOOLEAN"/>
		<db-attribute name="modifiedOn" type="TIMESTAMP"/>
		<db-attribute name="name" type="VARCHAR" length="512"/>
		<db-attribute name="nodeType" type="VARCHAR" length="128"/>
</db-entity>
<obj-entity name="AbstractNode"  
className="ish.oncourse.server.cayenne.AbstractNode"  
clientClassName="ish.oncourse.cayenne.AbstractNode" lock- 
type="optimistic" dbEntityName="AbstractNode"  
superClassName="ish.oncourse.server.cayenne.glue.CayenneDataObject"  
clientSuperClassName="ish.oncourse.cayenne.glue.PersistentObject">
		<qualifier><![CDATA[(isDeleted = null) or (isDeleted = 0)]]></ 
qualifier>
		<obj-attribute name="isDeleted" type="java.lang.Boolean" db- 
attribute-path="isDeleted"/>
		<obj-attribute name="modifiedOn" type="java.util.Date" db-attribute- 
path="modifiedOn"/>
		<obj-attribute name="name" type="java.lang.String" db-attribute- 
path="name"/>
		<obj-attribute name="nodeType" type="java.lang.String" db-attribute- 
path="nodeType"/>
</obj-entity>
<obj-entity name="DefaultNode" superEntityName="AbstractNode"  
className="ish.oncourse.server.cayenne. DefaultNode"  
clientClassName="ish.oncourse.cayenne. DefaultNode" lock- 
type="optimistic">
		<qualifier><![CDATA[nodeType = "D"]]></qualifier>
</obj-entity>

committing new objects works ok, but fetching the objects does not  
work (the presence of qualifier in DefaultNode does not matter):
getContext().performQuery(new SelectQuery(Term.class)) throws  
exception on server which does not tell much:

17/04/2007 19:05:31 com.caucho.hessian.server.HessianSkeleton invoke
WARNING: org.apache.cayenne.CayenneRuntimeException: [v.$ 
{project.version} ${project.build.date} ${project.build.time}]  
Exception processing message org.apache.cayenne.remote.QueryMessage
org.apache.cayenne.CayenneRuntimeException: [v.${project.version} $ 
{project.build.date} ${project.build.time}] Exception processing  
message org.apache.cayenne.remote.QueryMessage
         at  
org.apache.cayenne.remote.service.BaseRemoteService.processMessage 
(BaseRemoteService.java:169)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke 
(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke 
(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at com.caucho.hessian.server.HessianSkeleton.invoke 
(HessianSkeleton.java:157)
         at com.caucho.hessian.server.HessianServlet.service 
(HessianServlet.java:365)
         at ish.oncourse.server.CayenneServlet.service 
(CayenneServlet.java:102)
         at org.mortbay.jetty.servlet.ServletHolder.handle 
(ServletHolder.java:428)
         at org.mortbay.jetty.servlet.ServletHandler.dispatch 
(ServletHandler.java:677)
         at org.mortbay.jetty.servlet.ServletHandler.handle 
(ServletHandler.java:568)
         at org.mortbay.http.HttpContext.handle(HttpContext.java:1530)
         at org.mortbay.http.HttpContext.handle(HttpContext.java:1482)
         at org.mortbay.http.HttpServer.service(HttpServer.java:909)
         at org.mortbay.http.HttpConnection.service 
(HttpConnection.java:820)
         at org.mortbay.http.HttpConnection.handleNext 
(HttpConnection.java:986)
         at org.mortbay.http.HttpConnection.handle 
(HttpConnection.java:837)
         at org.mortbay.http.SocketListener.handleConnection 
(SocketListener.java:245)
         at org.mortbay.util.ThreadedServer.handle 
(ThreadedServer.java:357)
         at org.mortbay.util.ThreadPool$PoolThread.run 
(ThreadPool.java:534)


Is the inheritance functionality is supposed to work with remote  
persistence ? Maybe there is an error in our code ?

Marcin

Re: vertical inheritance

Posted by gilbertoca <gi...@gmail.com>.
gilbertoca wrote:
> 
> I know this is an old discussion, but I think cayenne has evoluted since
> than. :)
> 
> I'm trying this method [1] and again it (the cayenne docs) confuses me.
> I've followed it:
> mapping all 3 tables, and creating 1..1 relationship between PERSON and
> subclass tables(NATURAL_PERSON and LEGAL_ENTITY) [2]
> When I try to set subclass-specific attributes as "flattened attributes",
> the relationship aren't present [3].
> Can someone take a look at it[4]? Maybe I've missed something obvious!
> 

Yes! I've missed this note[1]:


> root table ("Table/View" for subclasses is still "BOOK"). [2]
> 



Regards,

Gilberto

[1] http://cayenne.apache.org/doc/modeling-vertical-inheritance.html
[2]
http://dl.dropbox.com/u/9093640/TableViewOfSubClassesMustBeTheRootTable.png

--
View this message in context: http://cayenne.195.n3.nabble.com/vertical-inheritance-tp4207p3064650.html
Sent from the Cayenne - User mailing list archive at Nabble.com.

Re: vertical inheritance

Posted by gilbertoca <gi...@gmail.com>.
I know this is an old discussion, but I think cayenne has evoluted since
than. :)

I'm trying this method [1] and again it (the cayenne docs) confuses me. I've
followed it:
mapping all 3 tables, and creating 1..1 relationship between PERSON and
subclass tables(NATURAL_PERSON and LEGAL_ENTITY) [2]
When I try to set subclass-specific attributes as "flattened attributes",
the relationship aren't present [3].
Can someone take a look at it[4]? Maybe I've missed something obvious!

Regards,

Gilberto


[1]http://cayenne.apache.org/doc/modeling-vertical-inheritance.html
[2]
http://construtor.googlecode.com/svn/trunk/click-orm-integration/docs/park-er.pdf
[3] http://dl.dropbox.com/u/9093640/objAttributeInspector01.png
[4]
http://code.google.com/p/construtor/source/browse/trunk/click-orm-integration/park-cayenne/src/main/resources/ParkMap.map.xml
-- 
View this message in context: http://cayenne.195.n3.nabble.com/vertical-inheritance-tp4207p1644921.html
Sent from the Cayenne - User mailing list archive at Nabble.com.

Re: vertical inheritance

Posted by Mike Kienenberger <mk...@gmail.com>.
Vertical inheritance is not natively supported by Cayenne yet
(although it will need to be to be JPA-compliant, so it'll happen
sooner rather than later).

I've made it work by creating custom templates which override
setPersistenceState() and then being careful how I construct queries.

http://cwiki.apache.org/CAY/is-inheritance-supported.html

I'm sure you'd need to do additional work to get it working with ROP.


On 4/17/07, Marcin Skladaniec <ma...@ish.com.au> wrote:
> Hi
>
> In our project we have tried using inheritance, this is the
> simplification of the map we are using:
>
> <db-entity name="AbstractNode">
>                 <db-attribute name="id" type="INTEGER" isPrimaryKey="true"
> isMandatory="true"/>
>                 <db-attribute name="isDeleted" type="BOOLEAN"/>
>                 <db-attribute name="modifiedOn" type="TIMESTAMP"/>
>                 <db-attribute name="name" type="VARCHAR" length="512"/>
>                 <db-attribute name="nodeType" type="VARCHAR" length="128"/>
> </db-entity>
> <obj-entity name="AbstractNode"
> className="ish.oncourse.server.cayenne.AbstractNode"
> clientClassName="ish.oncourse.cayenne.AbstractNode" lock-
> type="optimistic" dbEntityName="AbstractNode"
> superClassName="ish.oncourse.server.cayenne.glue.CayenneDataObject"
> clientSuperClassName="ish.oncourse.cayenne.glue.PersistentObject">
>                 <qualifier><![CDATA[(isDeleted = null) or (isDeleted = 0)]]></
> qualifier>
>                 <obj-attribute name="isDeleted" type="java.lang.Boolean" db-
> attribute-path="isDeleted"/>
>                 <obj-attribute name="modifiedOn" type="java.util.Date" db-attribute-
> path="modifiedOn"/>
>                 <obj-attribute name="name" type="java.lang.String" db-attribute-
> path="name"/>
>                 <obj-attribute name="nodeType" type="java.lang.String" db-attribute-
> path="nodeType"/>
> </obj-entity>
> <obj-entity name="DefaultNode" superEntityName="AbstractNode"
> className="ish.oncourse.server.cayenne. DefaultNode"
> clientClassName="ish.oncourse.cayenne. DefaultNode" lock-
> type="optimistic">
>                 <qualifier><![CDATA[nodeType = "D"]]></qualifier>
> </obj-entity>
>
> committing new objects works ok, but fetching the objects does not
> work (the presence of qualifier in DefaultNode does not matter):
> getContext().performQuery(new SelectQuery(Term.class)) throws
> exception on server which does not tell much:
>
> 17/04/2007 19:05:31 com.caucho.hessian.server.HessianSkeleton invoke
> WARNING: org.apache.cayenne.CayenneRuntimeException: [v.$
> {project.version} ${project.build.date} ${project.build.time}]
> Exception processing message org.apache.cayenne.remote.QueryMessage
> org.apache.cayenne.CayenneRuntimeException: [v.${project.version} $
> {project.build.date} ${project.build.time}] Exception processing
> message org.apache.cayenne.remote.QueryMessage
>          at
> org.apache.cayenne.remote.service.BaseRemoteService.processMessage
> (BaseRemoteService.java:169)
>          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>          at sun.reflect.NativeMethodAccessorImpl.invoke
> (NativeMethodAccessorImpl.java:39)
>          at sun.reflect.DelegatingMethodAccessorImpl.invoke
> (DelegatingMethodAccessorImpl.java:25)
>          at java.lang.reflect.Method.invoke(Method.java:585)
>          at com.caucho.hessian.server.HessianSkeleton.invoke
> (HessianSkeleton.java:157)
>          at com.caucho.hessian.server.HessianServlet.service
> (HessianServlet.java:365)
>          at ish.oncourse.server.CayenneServlet.service
> (CayenneServlet.java:102)
>          at org.mortbay.jetty.servlet.ServletHolder.handle
> (ServletHolder.java:428)
>          at org.mortbay.jetty.servlet.ServletHandler.dispatch
> (ServletHandler.java:677)
>          at org.mortbay.jetty.servlet.ServletHandler.handle
> (ServletHandler.java:568)
>          at org.mortbay.http.HttpContext.handle(HttpContext.java:1530)
>          at org.mortbay.http.HttpContext.handle(HttpContext.java:1482)
>          at org.mortbay.http.HttpServer.service(HttpServer.java:909)
>          at org.mortbay.http.HttpConnection.service
> (HttpConnection.java:820)
>          at org.mortbay.http.HttpConnection.handleNext
> (HttpConnection.java:986)
>          at org.mortbay.http.HttpConnection.handle
> (HttpConnection.java:837)
>          at org.mortbay.http.SocketListener.handleConnection
> (SocketListener.java:245)
>          at org.mortbay.util.ThreadedServer.handle
> (ThreadedServer.java:357)
>          at org.mortbay.util.ThreadPool$PoolThread.run
> (ThreadPool.java:534)
>
>
> Is the inheritance functionality is supposed to work with remote
> persistence ? Maybe there is an error in our code ?
>
> Marcin