<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: An Easier Java ORM: Relations</title>
	<atom:link href="http://www.codecommit.com/blog/java/an-easier-java-orm-relations/feed" rel="self" type="application/rss+xml" />
	<link>http://www.codecommit.com/blog/java/an-easier-java-orm-relations</link>
	<description>(permanently in beta)</description>
	<lastBuildDate>Sun, 29 Aug 2010 20:01:44 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: nla</title>
		<link>http://www.codecommit.com/blog/java/an-easier-java-orm-relations/comment-page-1#comment-4964</link>
		<dc:creator>nla</dc:creator>
		<pubDate>Thu, 22 Apr 2010 04:43:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.danielspiewak.com/java/an-easier-java-orm-relations#comment-4964</guid>
		<description>How can i delete the SQL log or make it stop appearing whenever i run my program.
The SQL log sth like above:

SQL statements from AO log:

8.8.2007 21:02:21 net.java.ao.EntityManager find
INFO: SELECT id FROM person WHERE id&gt;1
8.8.2007 21:02:22 net.java.ao.EntityProxy invokeGetter
INFO: SELECT firstname FROM person WHERE id = ?
8.8.2007 21:02:22 net.java.ao.DatabaseProvider executeInsertReturningKeys
INFO: INSERT INTO resource (id) VALUES (DEFAULT)
8.8.2007 21:02:22 net.java.ao.EntityProxy invokeGetter
INFO: SELECT name FROM resource WHERE id = ?
8.8.2007 21:02:22 net.java.ao.EntityProxy save
INFO: UPDATE resource SET name = ? WHERE id = ?
8.8.2007 21:02:22 net.java.ao.DatabaseProvider executeInsertReturningKeys
INFO: INSERT INTO baseEvent (id) VALUES (DEFAULT)
8.8.2007 21:02:22 net.java.ao.EntityProxy invokeGetter
INFO: SELECT resourceID FROM baseEvent WHERE id = ?
8.8.2007 21:02:22 net.java.ao.EntityProxy invokeGetter
INFO: SELECT user1ID FROM baseEvent WHERE id = ?
8.8.2007 21:02:22 net.java.ao.EntityProxy invokeGetter
INFO: SELECT user2ID FROM baseEvent WHERE id = ?
8.8.2007 21:02:22 net.java.ao.EntityProxy invokeGetter
INFO: SELECT user3ID FROM baseEvent WHERE id = ?
8.8.2007 21:02:22 net.java.ao.EntityProxy invokeGetter
INFO: SELECT title FROM baseEvent WHERE id = ?
8.8.2007 21:02:22 net.java.ao.EntityProxy save
INFO: UPDATE baseEvent SET resourceID = ?,user1ID = ?,user2ID = ?,user3ID = ?,title = ? WHERE id = ?</description>
		<content:encoded><![CDATA[<p>How can i delete the SQL log or make it stop appearing whenever i run my program.<br />
The SQL log sth like above:</p>
<p>SQL statements from AO log:</p>
<p>8.8.2007 21:02:21 net.java.ao.EntityManager find<br />
INFO: SELECT id FROM person WHERE id&gt;1<br />
8.8.2007 21:02:22 net.java.ao.EntityProxy invokeGetter<br />
INFO: SELECT firstname FROM person WHERE id = ?<br />
8.8.2007 21:02:22 net.java.ao.DatabaseProvider executeInsertReturningKeys<br />
INFO: INSERT INTO resource (id) VALUES (DEFAULT)<br />
8.8.2007 21:02:22 net.java.ao.EntityProxy invokeGetter<br />
INFO: SELECT name FROM resource WHERE id = ?<br />
8.8.2007 21:02:22 net.java.ao.EntityProxy save<br />
INFO: UPDATE resource SET name = ? WHERE id = ?<br />
8.8.2007 21:02:22 net.java.ao.DatabaseProvider executeInsertReturningKeys<br />
INFO: INSERT INTO baseEvent (id) VALUES (DEFAULT)<br />
8.8.2007 21:02:22 net.java.ao.EntityProxy invokeGetter<br />
INFO: SELECT resourceID FROM baseEvent WHERE id = ?<br />
8.8.2007 21:02:22 net.java.ao.EntityProxy invokeGetter<br />
INFO: SELECT user1ID FROM baseEvent WHERE id = ?<br />
8.8.2007 21:02:22 net.java.ao.EntityProxy invokeGetter<br />
INFO: SELECT user2ID FROM baseEvent WHERE id = ?<br />
8.8.2007 21:02:22 net.java.ao.EntityProxy invokeGetter<br />
INFO: SELECT user3ID FROM baseEvent WHERE id = ?<br />
8.8.2007 21:02:22 net.java.ao.EntityProxy invokeGetter<br />
INFO: SELECT title FROM baseEvent WHERE id = ?<br />
8.8.2007 21:02:22 net.java.ao.EntityProxy save<br />
INFO: UPDATE baseEvent SET resourceID = ?,user1ID = ?,user2ID = ?,user3ID = ?,title = ? WHERE id = ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: web development comp</title>
		<link>http://www.codecommit.com/blog/java/an-easier-java-orm-relations/comment-page-1#comment-4873</link>
		<dc:creator>web development comp</dc:creator>
		<pubDate>Mon, 10 Aug 2009 16:17:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.danielspiewak.com/java/an-easier-java-orm-relations#comment-4873</guid>
		<description>very nice approach, but I&#039;m a C# developer so cant really use it, shame!</description>
		<content:encoded><![CDATA[<p>very nice approach, but I&#8217;m a C# developer so cant really use it, shame!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Spiewak</title>
		<link>http://www.codecommit.com/blog/java/an-easier-java-orm-relations/comment-page-1#comment-2430</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Mon, 29 Oct 2007 17:11:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.danielspiewak.com/java/an-easier-java-orm-relations#comment-2430</guid>
		<description>@johan

That&#039;s right.  Though, you&#039;re missing an annotation there to make the getChildCategories() method work:

public interface Category extends Entity {
    public Category getParent();
    public void setParent(Category parent);

    @OneToMany
    public Category[] getChildren();
}

Something like that should work just fine, since a tree structure is really just a recursive one-to-many mapping</description>
		<content:encoded><![CDATA[<p>@johan</p>
<p>That&#8217;s right.  Though, you&#8217;re missing an annotation there to make the getChildCategories() method work:</p>
<p>public interface Category extends Entity {<br />
    public Category getParent();<br />
    public void setParent(Category parent);</p>
<p>    @OneToMany<br />
    public Category[] getChildren();<br />
}</p>
<p>Something like that should work just fine, since a tree structure is really just a recursive one-to-many mapping</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: johan</title>
		<link>http://www.codecommit.com/blog/java/an-easier-java-orm-relations/comment-page-1#comment-2427</link>
		<dc:creator>johan</dc:creator>
		<pubDate>Mon, 29 Oct 2007 15:29:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.danielspiewak.com/java/an-easier-java-orm-relations#comment-2427</guid>
		<description>What is the right mapping to realize a tree structure of a single entity. Let&#039;s say you have a Category entity. A Category can have a parent category and x-child categories.

interface Category extends Entity {
  Category getParentCategory();

  Category[] getChildCategries();
}

Any thoughts are appreciated.</description>
		<content:encoded><![CDATA[<p>What is the right mapping to realize a tree structure of a single entity. Let&#8217;s say you have a Category entity. A Category can have a parent category and x-child categories.</p>
<p>interface Category extends Entity {<br />
  Category getParentCategory();</p>
<p>  Category[] getChildCategries();<br />
}</p>
<p>Any thoughts are appreciated.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Marko</title>
		<link>http://www.codecommit.com/blog/java/an-easier-java-orm-relations/comment-page-1#comment-2117</link>
		<dc:creator>David Marko</dc:creator>
		<pubDate>Thu, 09 Aug 2007 05:55:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.danielspiewak.com/java/an-easier-java-orm-relations#comment-2117</guid>
		<description>Also to lazy-loading, ROR uses :include clause so developer have a full controll, or Django uses select_related() when fetching objects. Moving the lazy-load decision on developer is better way as developer knows what is the est for current situation.</description>
		<content:encoded><![CDATA[<p>Also to lazy-loading, ROR uses :include clause so developer have a full controll, or Django uses select_related() when fetching objects. Moving the lazy-load decision on developer is better way as developer knows what is the est for current situation.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Marko</title>
		<link>http://www.codecommit.com/blog/java/an-easier-java-orm-relations/comment-page-1#comment-2116</link>
		<dc:creator>David Marko</dc:creator>
		<pubDate>Thu, 09 Aug 2007 05:50:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.danielspiewak.com/java/an-easier-java-orm-relations#comment-2116</guid>
		<description>At the beginning of the code I have:
Person[] p_all=manager.find(Person.class,&quot;id&gt;1″);

One would expect that this will load all person objects into memory. I think its very common scenario, that you load e.g. some articles with specific criteria and list all titles in browser. But current mechanism hits database for each article title, what is inefficent. I think, that primary fetched objects should be fetch immediately as one expects. But e.g. when article has relationship with autor, the author can be fetch when needed(lazy-loading).

Current lazy-loading is very aggressive :-)</description>
		<content:encoded><![CDATA[<p>At the beginning of the code I have:<br />
Person[] p_all=manager.find(Person.class,&#8221;id&gt;1″);</p>
<p>One would expect that this will load all person objects into memory. I think its very common scenario, that you load e.g. some articles with specific criteria and list all titles in browser. But current mechanism hits database for each article title, what is inefficent. I think, that primary fetched objects should be fetch immediately as one expects. But e.g. when article has relationship with autor, the author can be fetch when needed(lazy-loading).</p>
<p>Current lazy-loading is very aggressive <img src='http://www.codecommit.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Spiewak</title>
		<link>http://www.codecommit.com/blog/java/an-easier-java-orm-relations/comment-page-1#comment-2109</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Wed, 08 Aug 2007 23:10:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.danielspiewak.com/java/an-easier-java-orm-relations#comment-2109</guid>
		<description>Possibly, there should be some mechanism to deactivate the lazy loading, or at least override it in a less clumsy fashion than the Query.select(&quot;*&quot;).  What do you think?</description>
		<content:encoded><![CDATA[<p>Possibly, there should be some mechanism to deactivate the lazy loading, or at least override it in a less clumsy fashion than the Query.select(&#8220;*&#8221;).  What do you think?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Spiewak</title>
		<link>http://www.codecommit.com/blog/java/an-easier-java-orm-relations/comment-page-1#comment-2114</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Wed, 08 Aug 2007 23:03:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.danielspiewak.com/java/an-easier-java-orm-relations#comment-2114</guid>
		<description>The last batch of SELECTs seems really odd.  There should be a SELECT statement for the first line, the third line (getFirstName()), an INSERT for the create(), and two UPDATEs.  Is there any other (possibly  concurrent) code happening here?

As for the lazy-loading...  Yeah, it will execute a SELECT for any non-cached property.  By default, it does cache any values loaded on the initial find() eg:

Person[] people = manager.find(Person.class, Query.select(&quot;*&quot;).where(&quot;id &gt; ?&quot;, 1));
people[0].getFirstName();    // no SELECT will be executed here since the value is already cached

You don&#039;t really see the advantages of the constant lazy-loading in a short running application.  In fact, for anything which doesn&#039;t hit the properties several times and/or have large result sets, lazy-loading is a bad idea (which is why I added the Query.select(&quot;*&quot;) mechanism).  However, when you&#039;ve got a long running application, a webapp for instance, it really starts to save on performance and memory over time.  Granted, in the short run it is more query intensive (which is annoying), but it buys you a lot in that it only grabs the values it needs as it needs them, and there&#039;s never any SELECT * FROM blah JOIN blah2.</description>
		<content:encoded><![CDATA[<p>The last batch of SELECTs seems really odd.  There should be a SELECT statement for the first line, the third line (getFirstName()), an INSERT for the create(), and two UPDATEs.  Is there any other (possibly  concurrent) code happening here?</p>
<p>As for the lazy-loading&#8230;  Yeah, it will execute a SELECT for any non-cached property.  By default, it does cache any values loaded on the initial find() eg:</p>
<p>Person[] people = manager.find(Person.class, Query.select(&#8220;*&#8221;).where(&#8220;id &gt; ?&#8221;, 1));<br />
people[0].getFirstName();    // no SELECT will be executed here since the value is already cached</p>
<p>You don&#8217;t really see the advantages of the constant lazy-loading in a short running application.  In fact, for anything which doesn&#8217;t hit the properties several times and/or have large result sets, lazy-loading is a bad idea (which is why I added the Query.select(&#8220;*&#8221;) mechanism).  However, when you&#8217;ve got a long running application, a webapp for instance, it really starts to save on performance and memory over time.  Granted, in the short run it is more query intensive (which is annoying), but it buys you a lot in that it only grabs the values it needs as it needs them, and there&#8217;s never any SELECT * FROM blah JOIN blah2.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Marko</title>
		<link>http://www.codecommit.com/blog/java/an-easier-java-orm-relations/comment-page-1#comment-2110</link>
		<dc:creator>David Marko</dc:creator>
		<pubDate>Wed, 08 Aug 2007 19:12:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.danielspiewak.com/java/an-easier-java-orm-relations#comment-2110</guid>
		<description>AO lazyness behaves very strange when looking at log console with SQL statemes, that AO issues. Loot to following code snippet and see what I can see in log from AO. It seems that SELECT statement is ssued for every accessing each object property. Why it is or do I miss something?

Person[] p_all=manager.find(Person.class,&quot;id&gt;1&quot;);
Person p1=p_all[0];
Person p2=p_all[1];
Person p3=p_all[2];
System.out.println(p1.getFirstname());

Resource r=manager.create(Resource.class);
r.setName(&quot;Server SARAH&quot;);
r.save();

BaseEvent b1=manager.create(BaseEvent.class);
b1.setResource(r);
b1.setUser1(p1);
b1.setUser2(p2);
b1.setUser3(p3);
b1.setTitle(&quot;Kontrola běhu Lotus NOtes&quot;);
b1.save();

SQL statements from AO log:

8.8.2007 21:02:21 net.java.ao.EntityManager find
INFO: SELECT id FROM person WHERE id&gt;1
8.8.2007 21:02:22 net.java.ao.EntityProxy invokeGetter
INFO: SELECT firstname FROM person WHERE id = ?
8.8.2007 21:02:22 net.java.ao.DatabaseProvider executeInsertReturningKeys
INFO: INSERT INTO resource (id) VALUES (DEFAULT)
8.8.2007 21:02:22 net.java.ao.EntityProxy invokeGetter
INFO: SELECT name FROM resource WHERE id = ?
8.8.2007 21:02:22 net.java.ao.EntityProxy save
INFO: UPDATE resource SET name = ? WHERE id = ?
8.8.2007 21:02:22 net.java.ao.DatabaseProvider executeInsertReturningKeys
INFO: INSERT INTO baseEvent (id) VALUES (DEFAULT)
8.8.2007 21:02:22 net.java.ao.EntityProxy invokeGetter
INFO: SELECT resourceID FROM baseEvent WHERE id = ?
8.8.2007 21:02:22 net.java.ao.EntityProxy invokeGetter
INFO: SELECT user1ID FROM baseEvent WHERE id = ?
8.8.2007 21:02:22 net.java.ao.EntityProxy invokeGetter
INFO: SELECT user2ID FROM baseEvent WHERE id = ?
8.8.2007 21:02:22 net.java.ao.EntityProxy invokeGetter
INFO: SELECT user3ID FROM baseEvent WHERE id = ?
8.8.2007 21:02:22 net.java.ao.EntityProxy invokeGetter
INFO: SELECT title FROM baseEvent WHERE id = ?
8.8.2007 21:02:22 net.java.ao.EntityProxy save
INFO: UPDATE baseEvent SET resourceID = ?,user1ID = ?,user2ID = ?,user3ID = ?,title = ? WHERE id = ?</description>
		<content:encoded><![CDATA[<p>AO lazyness behaves very strange when looking at log console with SQL statemes, that AO issues. Loot to following code snippet and see what I can see in log from AO. It seems that SELECT statement is ssued for every accessing each object property. Why it is or do I miss something?</p>
<p>Person[] p_all=manager.find(Person.class,&#8221;id&gt;1&#8243;);<br />
Person p1=p_all[0];<br />
Person p2=p_all[1];<br />
Person p3=p_all[2];<br />
System.out.println(p1.getFirstname());</p>
<p>Resource r=manager.create(Resource.class);<br />
r.setName(&#8220;Server SARAH&#8221;);<br />
r.save();</p>
<p>BaseEvent b1=manager.create(BaseEvent.class);<br />
b1.setResource(r);<br />
b1.setUser1(p1);<br />
b1.setUser2(p2);<br />
b1.setUser3(p3);<br />
b1.setTitle(&#8220;Kontrola běhu Lotus NOtes&#8221;);<br />
b1.save();</p>
<p>SQL statements from AO log:</p>
<p>8.8.2007 21:02:21 net.java.ao.EntityManager find<br />
INFO: SELECT id FROM person WHERE id&gt;1<br />
8.8.2007 21:02:22 net.java.ao.EntityProxy invokeGetter<br />
INFO: SELECT firstname FROM person WHERE id = ?<br />
8.8.2007 21:02:22 net.java.ao.DatabaseProvider executeInsertReturningKeys<br />
INFO: INSERT INTO resource (id) VALUES (DEFAULT)<br />
8.8.2007 21:02:22 net.java.ao.EntityProxy invokeGetter<br />
INFO: SELECT name FROM resource WHERE id = ?<br />
8.8.2007 21:02:22 net.java.ao.EntityProxy save<br />
INFO: UPDATE resource SET name = ? WHERE id = ?<br />
8.8.2007 21:02:22 net.java.ao.DatabaseProvider executeInsertReturningKeys<br />
INFO: INSERT INTO baseEvent (id) VALUES (DEFAULT)<br />
8.8.2007 21:02:22 net.java.ao.EntityProxy invokeGetter<br />
INFO: SELECT resourceID FROM baseEvent WHERE id = ?<br />
8.8.2007 21:02:22 net.java.ao.EntityProxy invokeGetter<br />
INFO: SELECT user1ID FROM baseEvent WHERE id = ?<br />
8.8.2007 21:02:22 net.java.ao.EntityProxy invokeGetter<br />
INFO: SELECT user2ID FROM baseEvent WHERE id = ?<br />
8.8.2007 21:02:22 net.java.ao.EntityProxy invokeGetter<br />
INFO: SELECT user3ID FROM baseEvent WHERE id = ?<br />
8.8.2007 21:02:22 net.java.ao.EntityProxy invokeGetter<br />
INFO: SELECT title FROM baseEvent WHERE id = ?<br />
8.8.2007 21:02:22 net.java.ao.EntityProxy save<br />
INFO: UPDATE baseEvent SET resourceID = ?,user1ID = ?,user2ID = ?,user3ID = ?,title = ? WHERE id = ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Spiewak</title>
		<link>http://www.codecommit.com/blog/java/an-easier-java-orm-relations/comment-page-1#comment-2111</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Wed, 08 Aug 2007 05:16:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.danielspiewak.com/java/an-easier-java-orm-relations#comment-2111</guid>
		<description>Oh, I just committed a slightly easier syntax (in Person):

@OneToMany(&quot;user1&quot;)
public Event[] getEventsForUser1();

@OneToMany(&quot;user2&quot;, &quot;user3&quot;)
public Event[] getEventsForOtherUsers();

I haven&#039;t tested it yet, but the changes were minimal to the existing code, so it should work nicely.</description>
		<content:encoded><![CDATA[<p>Oh, I just committed a slightly easier syntax (in Person):</p>
<p>@OneToMany(&#8220;user1&#8243;)<br />
public Event[] getEventsForUser1();</p>
<p>@OneToMany(&#8220;user2&#8243;, &#8220;user3&#8243;)<br />
public Event[] getEventsForOtherUsers();</p>
<p>I haven&#8217;t tested it yet, but the changes were minimal to the existing code, so it should work nicely.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
