Faisal Mahmoud

Greenhorn
+ Follow
since Oct 08, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Faisal Mahmoud

Hi,

I have a webapp with JSF as the view technology, Hibernate 3 for persistence and Spring. What I have trouble conceptualizing is the coordination with persistent entities and their corresponding view entities when a bi-directional association exists between entities.

For example, I have the following entities:

1. A File object.
2. A Catalog object.
3. A User object.

A User has 0...N Catalog objects. Therefore in a User class, there is a List of Catalog objects. This is specified in the User.hbm.xml file using a <list> element. In the Catalog class, I have a reference to a User object; which is denoted in the Catalog.hbm.xml file with a <many-to-one> element. There is a foriegn key restraint on the Catalog table where the User_Id column refers to the User_Id column in the Users table.

A Catalog has 1...N File objects. The Catalog & File classes have similar <set> and <many-to-one> elements in their xml files as described above for User and Catalog objects.

Now I have tried two approaches to coordinating between what must be displayed in the View layer and the Model layer. One approach was to have my View classes extend their corresponding Model class, with the persistent properties being declared as protected in the Model class. However, I have a problem because a User object has a List of Catalog objects, while a UserView object needs to have a List of CatalogView objects. So there exist two different List objects in the UserView object, where, there should really be only one list. And I have trouble coordinating these two lists when I have to persist data that has changed in the View.

The other approach was to have seperate classes for the Model & View, and use a Builder strategy to generate one type of class from the other. But the problem here is that, for example, the association is bi-directional. So lets say a Catalog has changed state in the View, then I need to persist it. So a CatalogBuilder will take a CatalogView object and attempt to generate a Catalog object. However, the CatalogView has a reference to a UserView object, so a UserBuilder must be employed to generate a User object for the corresponding UserView object the CatalogView contains a reference to. But again, this UserView has a reference to a List of CatalogView objects, which then require a CatalogBuilder to generate corresponding Catalog objects for. You can see how this will go on forever then.

So how do I approach this problem?
Hi,

I am writing a web app with the following technologies:

Java 1.4.2
Tomcat 5.0.28
JSF 1.1_01
Spring 1.2
Hibernate 3
PostGreSql 8.0.4

I have a table called Tenants in my DB. The DDL is as follows:


I try to return a java.util.List of all Tenant objects mapped to this table, but I get an exception:

java.sql.SQLException: ERROR: relation "public.tenants" does not exist. I'm guessing this is problem with configuration. Because the schema and table do exist and there is data in there. Below is the log output and exception stacktrace, and below that is more information about how my app is setup and things are mapped.

Log Output & Stacktrace


Here is how Hibernate is setup in the Spring applicationContext.xml file:


Below are the Tenant object and the hibernate mapping file for this table:




This is the TenantDAO and its' implementation:


Any help would be appreciated.

Thanks!
-Faisal
[ December 30, 2005: Message edited by: Faisal Mahmoud ]