Win a copy of Spring Boot in Practice this week in the Spring forum!

David Madouros

Greenhorn
+ Follow
since Mar 08, 2005
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 David Madouros

Instead of:

Here's the mapping in parent:
<set name="bookmarks" cascade="all" inverse="true">
<key column="member_id"/>
<one-to-many class="Bookmark"/>
</set>



Try:


The inverse attribute usually indicates a bidirectional association and can have odd effects when included in unidirectional relationships.
[ October 20, 2007: Message edited by: David Madouros ]
This feels like more a hack than anything, but...

The problem is that mysql converts dates to numerics when you add or subtract. For example, current_date = 2007-04-20, but (current_date + 0) = 20070420. A solution (hack) for this is to do the following:



Ugly, but it works.
Casey

I'll take a best guess at the solution to your problem...
To restate your issue: you cannot cast your results into Coordinator objects.

This is happening because you are joining tables explicitly (without fetching). What you get back as your results is a list of Object[] (List<Object[]> . The first element in your array is the Coordinator and the second is the Doctor. From what I can tell, this explicit join is unnecessary for two reasons:

1) Since you are looking for the doctor.id in the where clause, the keyword 'left' is unnecessary. You will always only get rows bach that have a matching doctor.

2) Hibernate allows you to use implicity joins that traverse the object graph and allow you to use those values in your where clause. Unlike an explicit join, this will only return to you a List of object in your from clause (List<Doctor> .

For example:
Your query will probably give you back what you want if it were coded like this:
Ankur,

When you use 'select' in either an HQL or native SQL query, Hibernate does not return the object in your 'from' clause. Just as when using non-Hibernate SQL, 'select event.* ...' returns all the columns from the event table. The List you get back from your query is a list of Object[] (object arrays). Each element in the list is an array of Objects and each element in the array represents one column in the event table.

For example, if I have a table defined as:

that contains the following data:

and I use a Hibernate SQL query as follows:

I get a List of Object[]. The first element in the List represents the first row in my result set:

Object[0] is of type BigInteger and has a value of 1
Object[1] is of type String and has a value of "Madouros"

The second element in the List represents the second row in my result set:
Object[0] is of type BigInteger and has a value of 2
Object[1] is of type String and has a value of "Johnston"

etc.

Not seeing your tables, I cannot say exactly what you get back. But, this should give you the idea.
I think that quite simply you are just missing your transaction calls. My understanding is that you need to begin and commit/rollback a transaction anytime you save or update.


[ March 29, 2007: Message edited by: David Madouros ]
Jay,

I'm inclined to say no it's not a flaw in hibernate's architecture.

I don't understand how you can have a passenger in a car, update the passenger and not see the change reflected in the passenger if it all takes place in a single transaction.

The only way that I can see this happenning is if you go out of your way to retrieve the car and it's passengers and store car somewhere (perhaps in an HTTPSession). Then at some later point, you retrieve a passenger from the database (that also happens to be a passenger in car),update that passenger, and expect the passenger in car in session to be automagically updated. It makes sense to me that the passenger in the car is stale. If this is the case, then I agree that hibernate does not offer a better solution for this problem than straight jdbc.

Honestly, I'm feeling kind of dense at the moment, cause I don't understand where you're coming from. I've used hibernate for several projects both personal and professional and I don't recall this being an issue. Not to say that I know it all (I most certainly do not), just that I don't get it.
Isn't DispatchAction struts? Can you be more specific about what you are trying to do?
[ March 11, 2007: Message edited by: David Madouros ]
Jay,

If you could post your hibernate transaction boundaries it would be very helpful. Without them the best I can do is make assumptions. Here goes:

Transaction #1
You get a Car out of the database.

Transaction #2
You get a Passenger our of the database.
You update (and save) the Passenger.

Post-Transactions
You refresh the Passenger. (Transaction #3?)
You iterate through the collection of passengers in Car and don't see the update.

Based on these assumptions, I would suggest two things to keep your objects in sync:
1) get the passenger object out of the car's collection of passengers and update that. Then save either the passenger or the car.
- OR -
2) call refresh on car instead of passenger.

Note: A transaction, in this case, is the opening and closing of a Hibernate Session.

Hope that helps.
If you want the actual ContactName objects back, try using any of the follwing:



Personally, I prefer the first example.

Also, using 'select n.id' will return a List of Long/Integer (depending on how you defined id) if that's what you were trying to do.
[ March 08, 2007: Message edited by: David Madouros ]
Madhuchilipi,

Anytime you use aggregation in HQL (max, min, count, sum, etc.), you do not get an instance of your object back. You only get a single column value (the max value of your 'sno' column as a Long in this case). To do what you are trying to do, you have to use a subselect. Your query should look like:



Note: You would have to use a subselect with SQL also.
Hey Raj,

This is what I probably should have said the first time...
I recreated your situation (see code below) and I only get the constraint violation if I save address without first saving employee. Could there be a difference in our implementations?


[ March 07, 2007: Message edited by: David Madouros ]
Make sure you are saving your instance of Employee and not Address. Let us know if it doesn't work.
Assuming you want the value of 'sname' as a String and that it is mapped as a string in a class named Madhu...



Hope this helps.
Without seeing your mappings or table structures I'll have to make some assumptions...

It sounds like your using the table-per-class hierarchy strategy (you have one table for all HeaderWarehouses). The closest you can come to having separate IDs for each subclass would be to change to the table-per-subclass strategy.

Something like...


This will give you one 'count' for all instance of HeaderWarehouse and separate counts of both InsertWarehouse and RetireWarehouse. Might not be exactly what you're looking for, but it's the best I can think of.
I recently installed JBoss and am working with the book -- JBoss at Work -- to learn how JBoss works. However, when I run the sample JSP pages with JSTL tags, I get the following error:

exception

javax.servlet.ServletException: javax.servlet.jsp.tagext.TagAttributeInfo.<init>(Ljava/lang/String;ZLjava/lang/String;ZZ)V
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:272)
javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

root cause

java.lang.NoSuchMethodError: javax.servlet.jsp.tagext.TagAttributeInfo.<init>(Ljava/lang/String;ZLjava/lang/String;ZZ)V
org.apache.jasper.compiler.TagLibraryInfoImpl.createAttribute(TagLibraryInfoImpl.java:572)
org.apache.jasper.compiler.TagLibraryInfoImpl.createTagInfo(TagLibraryInfoImpl.java:401)
org.apache.jasper.compiler.TagLibraryInfoImpl.parseTLD(TagLibraryInfoImpl.java:248)
org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:179)
org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:418)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:483)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1543)
org.apache.jasper.compiler.Parser.parse(Parser.java:126)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:211)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:100)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:146)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:853)



JBoss Version 4.0.2
Tomcat Version 5.5.9
Java SDK Version 1.4.2_10

Running everything out-of-the-box...

I googled this error and found that I'm not the only one this has happened to, however, all of the solultions appy to JBoss 3.x and the suggested solutions don't seem to apply to version 4.0.2.

Any help is appreciated.


DMad
16 years ago