Ylva Degerfeldt

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

Recent posts by Ylva Degerfeldt

Yes, I can connect to the database through MySQL Command Line Client.

Hi everyone,

I've got a really weird Hibernate problem and I'm hoping that one of you (who has used Hibernate and perhaps MySQL) has any ideas on how I could solve it.

I'm using Hibernate 3.2.6, MySQL Server 5.0.51a and Sun Java System Application Server 9.1.01 with NetBeans 5.5.1

The problem is that I can't connect to the database. When I try to do any kind of database operation I get these exceptions:

I can also add that this is a web application, that I'm using hbm.xml files and c3p0 as connection pool.

What's weird about this problem is that everything has worked earlier and since then I haven't changed a single thing.

What I have done is worked on another Hibernate application (not web but Java desktop app.) which uses another database with the same MySQL Server and the same NetBeans version. In this application I tried to autogenerate the database tables from the hbm.xml files using hbm2ddl, which didn't work. Only 2 out of 4 tables were generated and I couldn't see anything wrong with the mapping files. (It was possible, though, to save objects to the tables that were generated.

I'm thinking that the problems with the web application might have something to do with the database generation I tried to do with the desktop application. I know this sounds really strange but I can't find any other way of explaining it.

Anyway, the question is what I can do to make it work again. I would really appreciate any kind of advice on this matter.

Thanks in advance!

Best regards
Thank you, Cameron!

I created the database with an SQL command and after that I was able to generate some tables..

But the big problem is: only TWO tables out of four are generated. (Tell me if I should post this in a new thread. For the moment I'm putting it here.)
This is really weird because I See (in the console) that the "CREATE TABLE" and "ALTER TABLE" commands are run for all four tables, but later when I check in MySQL only two tables are there.

I'm getting no exceptions. That's also weird.

I'm wondering if this problem has anything to do with that I have composite-id mappings (including FK's) in some hbm.xml files and that they may not be correct. Could that be the case?

I tried to find this out by changing one of the hbm.xml files into not having any composite ids or foreign keys but then I got another problem:
Even after "clean and build" the table creation still tried to create the old version of that table.

Do I have to do something extra to tell hbm2ddl that I've made changes to the hbm.xml files?

Sorry for asking so many questions at once but I'm desperate and I Really Need help with this! (I have an extremely important deadline that I have to follow.)

Please help me!

Hello everyone,

I'm still a newbie at using Hibernate and now I'm trying to use the automatic schema generation feature (this thing called "hbm2ddl"), but for some reason it's not working so I'd like to know the correct way of doing it.

I'm using Hibernate3, MySQL and NetBeans 5.5.1 in an ordinary Java application.

I've written my Java POJOs, their mapping hbm.xml files and I've put (among other things) these lines in my hibernate.cfg.xml file:

I've also mapped the hbm.xml files to the cfg.xml file.

I thought I didn't have to do anything more than this to use the automatic schema generation. "Hibernate in Action" says that when using the "create" value of hbm2ddl, the database schema should be generated as soon as you've executed buildSessionFactory().

But I Am creating a SessionFactory in a static init method I have in my HibernateUtil class (according to many examples).

The problem is that nothing is happening. No database is showing up in NetBeans or in the MySQL console.

At least nothing was happening when I only tried to open and close a Session in Main (to try it out).

Then I added some code for manually trying to use that SchemaExport class like this:

And in Main I added calls to beginTransAction.
But after this, when I tried to run the application (more specifically in the call to session.beginTransaction())I got these exceptions:

"org.hibernate.exception.GenericJDBCException: Cannot open connection
Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!"

..which proves to me that the database has not been created.(Anyway, it's not shown anywhere.)

Am I supposed to add something to NetBeans's build-impl.xml or something to make this work?

Please help me! I'm lost.

Thanks in advance.

Ok, I thought about this some more and I realized that what I really needed was a "typical bidirectional one-to-one relationship". (If I remove the old Document Before I save the new one there's no need for many-to-one.)

Though, "Hibernate in Action" says that one side of this relationship must be mapped as many-to-one with a unique constraint, so I did this new mapping according to the book:

(In Client.hbm.xml):
<many-to-one name = "docRef" column = "docRef" unique = "true" class = "BusinessLogic.Entities.Document" cascade = "all" fetch = "join"/>

(In Document.hbm.xml):
<one-to-one name = "client" property-ref = "docRef" cascade = "save-update" class = "BusinessLogic.Entities.Client" fetch = "join"/>

I'll describe shortly what I'm trying to do and what causes a problem:
First I fetch the right Client object from the db.
Then a method checks if that Client had any old Documents saved and if so removes them (it should only be one). - This works.
Then a new Document is created and saved to the db, using the reference to that Client.
After this I set the docRef property of Client to point to the new Document, which also works.

What doesn't work is this: When I check the db after program execution the Client reference of the newly saved Document is NULL.

I tried to add a call to session.update for the new Document but that didn't help.

I've really thought hard about this and read my book but I'm not getting anywhere, so could you Please help me, Mark or anyone who can?


Thanks for your reply, Mark.

Yes, I do want cascade = "all" on the one-to-one side so I changed that.
But unfortunately it didn't help.
I also tried removing the cascade attribute from the many-to-one side since I don't think it's really needed, but that didn't help either.

What else could be the source of the problem?
-The value of "fetch"?
Or should I remove some other attribute?

Should one of the sides of the relationship have an "inverse" attribute? I'm not sure about this.. (Basically this relationship is one-to-one on both sides. There will just temporarily be more than one Document connected to a specific Client, before the Client's older Document is removed.)

I'll try to read more about this myself but I would appreciate some more help also.


Hi everyone,

This is a Hibernate problem.

I have an entity called "Document" which has a many-to-one relation to the entity "Client". But on the Client side the relation to Document is one-to-one since I only want to save a reference to the latest Document.

My problem now is this: First I want to create and persist a new Document including a reference to a Client, which works.

But then I want to set the "Document" reference in Client to point to the new Document. This works when I step through the java code but when I check the contents of the database later I find that the Client record in question still points to an old Document and not the new one.

I'm getting no errors. It just seems like that Client instance doesn't get updated in the db. What can be the reason for this?

I can add that I'm closing the Session through a filter and when I stepped through the code I saw that this happens after the relevant code has been executed (at least it looks that way), so that seems alright.

Maybe the problem is due to my Hibernate mapping files since I'm not absolutely sure I've written them correctly. Therefore I'm pasting the most relevant parts of them here:

<class name = "BusinessLogic.Entities.Document" table="document">
<many-to-one name = "client" column = "clientId" foreign-key= "clientId" class = "BusinessLogic.Entities.Client" cascade = "save-update" fetch = "join"/>

<class name= "BusinessLogic.Entities.Client" table = "client">
<one-to-one name = "docRef" foreign-key = "docRef" class = "BusinessLogic.Entities.Document" cascade = "delete"/>

I really hope somebody can help me with this. That would be great!

Thanks in advance!

Thank you for your reply, Tom.

Now though, that issue is no longer that important since I've changed the structure of my application to using a List instead of a HashMap.

I can mention anyway that "thisValue" is the current object (a String) of an iteration through a Set and that I think I tried the syntax you mentioned before I gave up.

Thanks anyway!

15 years ago
Q: What do you get if you cross a kangaroo and an elephant?
A: HUGE holes all over Australia.

Q: What do female elephants use as tampons?
A: Sheep.

(That was really ugly. I know..)
15 years ago
Hi everyone,

I'm trying to learn Struts 2 and my current problem is about accessing a property of a javabean stored in a HashMap, from a jsp.

The HashMap is stored in the session. This is the code that I've tried:

The javabean that the Map returns has getState- and setState methods, so I thought the code above would work (as long as Struts can find the type of the javabean. I'm wondering whether this is the problem).
But maybe it's a syntax problem about the '#'s.

I have also tried to print out the value, using:
<s roperty value = "#session.myMap[#thisValue].state"/>

But this prints nothing at all.

I've also tried
value = "%{#session.myMap[#thisValue].state}",
value = "#session.myMap[thisValue].state"
value = "#session.myMap[%{thisValue}].state

but none of them prints anything.

Please help me, anyone who can!
That would be really great!

15 years ago
Thanks again, Merrill!

I actually solved that problem. I had been stupid enough to only "Build Main project" and never do "Clean and Build..". When I did that the problem with the two places disappeared. (The struts2-core.. file disappeared from the topmost place on the server)

Now I have run into new Struts problems, but I think that has to be a new thread.

Thanks for now!

15 years ago
Thanks for your answer, Merrill!

You're right. I shouldn't have a Struts dependency in the EJB layer, so I managed to remove it (and removed all the struts related jars from the lib).

Though, that didn't help (which I was afraid would be the case). I still get the same exception, about the struts2-core- being in two places and I still can't remove it from either place.

Is there some sort of configuration file somewhere which has a redundant specification of the location of the struts2-core.. file?

Please help me with this!! I have no clue what to do and I really need to move on with and finish this project soon (for financial reasons)!


15 years ago
Hi everyone,

I'm trying to learn and use Struts 2 (actually migrating from Struts 1 to 2) and I have written lots of java and xml code, which should be working. I just can't run the application! When I try to, I get this

Caused by: Bean type class com.opensymphony.xwork2.ObjectFactory with
the name xwork has already been loaded by bean -
- bean - jar:file:/C:/Sun/AppServer/domains/domain1/applications/j2ee-apps/Extract_to_cv_2/Extract_to_cv_2-war_war/WEB-INF/lib/struts2-core-!/struts-default.xml:30:72

As the exception said, I found that the struts-core- file
was located in two places under my application on the server. I tried
to remove the topmost copy of the file but when I tried running the
app. again I got the same exception, and found that the file had been
put back there. Then I tried to remove the struts-core.. file that was
further down, but the same thing happened! (the same exception and the
file had been returned to that location as well).

I'm using NetBeans 5.5.1 and Sun Java System Application Server 9 and
my application is an enterprise application with a web module and an
ejb module. I'm wondering whether this problem is due to that I have
the struts2 jars in both the lib directory of the ejb module and the
lib directory of the web module. This might be stupid, but I needed
the ejb module to know about the struts classes as well and didn't
know how to make them visible to the whole application.

But then again, this (having struts jars in both modules) actually
worked when I was using Struts 1.

I'm really confused about this and I'm hoping that someone can help
me! Maybe this is mostly a NetBeans issue so if someone who has used
NetBeans could answer it would be great.

I feel completely lost when it comes to this kind of things (what's
happening "behind the scenes" in NetBeans and the app. server) but I'm
willing to learn from anyone who wants to explain it to me. But please
explain it very thoroughly then.

Please help me! I'm stuck.

15 years ago
Struts was bundled with NetBeans 5.5.1 but it seems like it's version 1.2 (according to the DTD used). Is it possible that there is a newer version of Struts (that is not Struts 2), where this works?

15 years ago