Win a copy of Spring in Action (5th edition) this week in the Spring forum!

Hanna Habashy

Ranch Hand
+ Follow
since Aug 20, 2003
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
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 Hanna Habashy

Never mind, it is Serializable.

I did a serialization/desirialization to prove it.

Thanks,
7 years ago
Hello:

In Java 6 is the following object serializable?

private final char[] myChars;

Or should I change the primitive type to Object Character?

Thanks,
7 years ago

Jeanne Boyarsky wrote:Is the error occuring on server startup or when you call the code to lookup the DataSource? If the later, are you using "java:comp/env/jdbc/MSSQLDataSource" as the name?



I get the error when I access the datasource. This is an old project that has been running for years. I am doing some maintinance on it, but I cannot deploy it locally.

I am struggling with this error for many hours now.
Tomcat 7.0 inside Eclipse 3.6

Server.xml



Web.xml




I tried first on Eclipse Galileo and Tomcat 6.2, then I upgraded to Eclipse 3.6 and Tomcat 7.0. Same error.

Any help is greatly appreciated.


Paul Sturrock wrote:Try changing the fetch mode.



The fetch mode in the .hbm file is set to join

I added this line:


crit = getHbnSession().createCriteria(User2Application.class, "u2a");
crit.add(Restrictions.eq("u2a.application.applicationId", appId));
crit = crit.setProjection(Property.forName("user"));
crit.setFetchMode(FetchMode.JOIN);
crit = crit.createCriteria("user", "u");



But, it didn't do anything different.

Any other ideas?

Three tables:
User - contains user information
application - contains applications information
user2application - a bridge table between user and application. Composed of primary key or user, and primary key of application

Query:
Retreive all users by application ID.

SQL:


I created this criteria, but not efficient. Produces a select statement for every user.


Is there any other efficient way?

Thanks



I am trying to implement pagination using Hibernate. I need to execute two criterias; one to return the rowCount and the other to execute the query itself.

I don't want to create two criteria objects, because it is redundant and some of my criteria are quite complicated with joins.

Is there any way to clone the criteria object?

On the hibernate forum, some suggests to use DetachedCriteria then Serialize and DeSerialize it; to me, it is very inefficient and slow.

I am using Hibernate 3.2

Thanks,

I need to call some stored procedure for reporting. The Store Proc. DO NOT return an entity, so I cannot configure them as name queries in a configuration files.

The only way I know is to:



The session.connection() method is deprecated, and I couldn't find any other way of obtaining a connection object.

Please advise how to obtain a connection object, and if there is any other way of calling a stored procedure.

Thanks

Rene Larsen wrote:Have you tried with rs.getTimestamp(1) ??



Thank you very much, this solved it.
I am trying to get the date from the database. I can read it fin, but the hour, minutes, and sec values are missing.
Here is a segment of my code:


The value in sqlDate returned is 2009-09-03, however the value returned from the database console is 2009-09-03 12:16:13.747

How can I get the full date?
I tried use Date.getTime(), cast it to java.util.Date, not it not working.

Your help is appreciated.
Thanks, I get it solved.

criteria = createCriteria(User2Book.class, "u2b")
crit.add(Restrictions.eq("u2p.category", value));
crit.setProjection(Property.forName("book"));
crit = crit.createCriteria("user");

Mansi Mishra. wrote:

Hanna Habashy wrote:

Mansi Mishra. wrote:Try this...

Can you elaborate on how this code going to return a list of books?

Thanks,



getHibernateTemplate.findByCriteria(criteria).add(Restrictions.eq("category", filterValue))

returns a list of User2Book objects filtered by "category" using the "filterValue"
All you need to do is fetch this into an arraylist of the same type



returns a list of User2Book objects.



Thanks for the response, but my question is how to return a list of books, not a list of User2Book.

Mansi Mishra. wrote:Try this...



Can you elaborate on how this code going to return a list of books?

Thanks,
If I have a class like this:


How can I create a criteria on this class that return a list of books only filtered by category?
P.S. I simplified the example I have to work with.

Thanks,

I have been developing in one database with no problem. The configuration line is:

<property name="hibernate.connection.url">jdbc:sqlserver://DEVD1;DatabaseName=myProject;SelectMethod=direct</property>

The sql statement generated always append the database name to the SQL query like this: myProject.dbo.<table name>

So, far no problem.

Now: I tried to point the mapping file to different instance for testing. The new configuration file is like this:

<property name="hibernate.connection.url">jdbc:sqlserver://DEVD2;DatabaseName=myProjectTest;SelectMethod=direct</property>

Now, notice the difference. The database name changed to myProjectTest, and the sql server changed to DEVD2

When I try to connect to this database, I get a lot of errors because the generated SQL is not correct. Hibernate appends the old database name to the sql like this: myProject.dbo.<table name>, and it is supposed to be myProjectTest.dbl.<table name>

Consequently, all of my unit test fails.

I cleaned the project many times. I manually deleted the class files. I inspected the print out in the console, and hibernate reads from the correct file. I closed Eclipse to clean the cach. But, the problem is still there.

Anyone has ever seen anything like this?
Any idea where else should I look for?

Thanks