Hibernate seems to support one-to-many relationships by creating HashSets in the bean for the "one" table. For example, if you have PRODUCT_TYPE and PRODUCT tables, Hibernate creates a HashSet in the PRODUCT_TYPE bean to hold a set of PRODUCT records for each PRODUCT_TYPE record.
I do not see this with Sql2java, which seems to create two independent beans. When you retrieve a PRODUCT_TYPE record into its bean, it does not include its set of related products.
Am I missing something?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry for the delay... It looks like I bypassed this post back then in December. Thanks to Horst for alerting about this in his post!
You are right that the generated code for the bean does not have any reference to the other referenced beans. However sql2java does generate the methods to load them. They are in the manager of the bean.
Following your example, you will find in the ProductTypeManager a method "Product[] getProducts(ProductType bean)" to retrieve from the database all the Product beans related to your ProductType bean.
You also have a method "setProduct(ProductType bean, Product related)" to establish the relation between your current ProductType and a new related Product.
Unlike Hibernate which enables both lazy and eager loading, sql2java generated code only permits lazy loading. Would you like to make it eager, you would need to modify the bean.java.vm template (and contribute it back as a patch;-).
Hope it is now clearer.
Alain
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks. That makes it clearer. I have to review my code. I think I was coding SQL to accomplish this. The "Product[] getProducts(ProductType bean)" methods should be simpler.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry, I did not mean that your genereated code should be simpler. I meant that my code would probably be simpler if I used your code properly, rather than writing my own SQL.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Brilliant! I was about to move from sql2java.
I have also modified a template to generate struts2 actions with CRUD functionality. Where should I put it, once I test them in my current project?
Regards
Aneesh
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hibernate seems to support one-to-many relationships by creating HashSets in the bean for the "one" table. For example, if you have PRODUCT_TYPE and PRODUCT tables, Hibernate creates a HashSet in the PRODUCT_TYPE bean to hold a set of PRODUCT records for each PRODUCT_TYPE record.
I do not see this with Sql2java, which seems to create two independent beans. When you retrieve a PRODUCT_TYPE record into its bean, it does not include its set of related products.
Am I missing something?
Sorry for the delay... It looks like I bypassed this post back then in December. Thanks to Horst for alerting about this in his post!
You are right that the generated code for the bean does not have any reference to the other referenced beans. However sql2java does generate the methods to load them. They are in the manager of the bean.
Following your example, you will find in the ProductTypeManager a method "Product[] getProducts(ProductType bean)" to retrieve from the database all the Product beans related to your ProductType bean.
You also have a method "setProduct(ProductType bean, Product related)" to establish the relation between your current ProductType and a new related Product.
Unlike Hibernate which enables both lazy and eager loading, sql2java generated code only permits lazy loading. Would you like to make it eager, you would need to modify the bean.java.vm template (and contribute it back as a patch;-).
Hope it is now clearer.
Alain
Thanks. That makes it clearer. I have to review my code. I think I was coding SQL to accomplish this. The "Product[] getProducts(ProductType bean)" methods should be simpler.
If you'd like to get some simpler code generated, please post an example of the resulting code you are expecting.
After all, many of the templates were contributed by users as you.
Sorry, I did not mean that your genereated code should be simpler. I meant that my code would probably be simpler if I used your code properly, rather than writing my own SQL.
Brilliant! I was about to move from sql2java.
I have also modified a template to generate struts2 actions with CRUD functionality. Where should I put it, once I test them in my current project?
Regards
Aneesh
Hi Aneesh,
Whenever you think your templates may be of some interest to the community, you can post them as a patch to the Patches Tracker:
http://sourceforge.net/tracker/?group_id=54687&atid=474469
From there, it will get merged to the next release as you may notice in the README's Change Log:
http://sql2java.cvs.sourceforge.net/sql2java/sql2java/doc/README.txt?view=markup
Thanks for contributing,
Alain