Hallo developers, I got this strange error that i'm going to explain.
Hibernate Version: --> 3.1.3
Mapping documents: --> they are in the hibernate.zip linked
Code between sessionFactory.openSession() and session.close(): -->
Code:
Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction(); session.save(platformInfo);
session.getTransaction().commit();
Name and version of the database you are using: --> Oracle 10g
I got these objects:
PlatformInfo
ContainerProfileInfo
PlatformInfo has a many-to-many association with ContainerProfileInfo
PlatformInfo N----->M ContainerProfileInfo
I implemented these associations in standard way so in code:
Code:
public class PlatformInfo extends PlatformElement {
String name; //key assigned
Collection<ContainerProfileInfo> containerProfiles = new HashSet<ContainerProfileInfo>();
...
}
Code:
public class ContainerProfileInfo extends PlatformElement{
private String name; //key assigned
...
}
When I create this object hierarchy "by hand" and i save the master object "PlatformInfo" i got what i expect on DB.
Code:
PlatformManager platformManager = new PlatformManager();
// Clean the DB
platformManager.deleteTables();
// Create the main bean
PlatformInfo platformInfo = new PlatformInfo(PLATFORM_KEY);
// Create the associated bean and assign it to the "father"
ContainerProfileInfo profileInfo = new ContainerProfileInfo("profile1");
platformInfo.addContainerProfile(profileInfo);
// Save the Bean
platformManager.store(platformInfo);
System.out.println(platformInfo.toString());
Then I load the just saved object from DB, delete records from DB and then i save it again.
Code:
// Load the "just saved" bean
PlatformInfo platformInfoLoaded = (PlatformInfo) platformManager.load(PlatformInfo.class, PLATFORM_KEY);
// Clean the DB and then resave it.... Here on DB i lose the association!!!
platformManager.deleteTables();
platformManager.store(platformInfoLoaded);
System.out.println(platformInfoLoaded.toString());
// Reload the "just saved" bean and check with toString that is no more consistent
PlatformInfo info = (PlatformInfo) platformManager.load(PlatformInfo.class, PLATFORM_KEY);
System.out.println(info.toString());
Now even if the objects are the same (they hold same data) if i check on DB the association between PlatformInfo and the ContainerProfile
is no more available.
Maybe i'm making some errors, but i couldn't understand where.
Anyone could help me please?
I attach a zip file with 2 ant target:
build: build the jar
run: run the test
If you want to use it you have to configure hibernate-cfg.xml with your own DB settings.
For those who use Eclipse there's also the .project file, just open it and modify build path to point at lib folder.
http://www.lafiocavenmola.it/modules/uploader/index.php?action=downloadfile&filename=hibernate.zipThanks for your time
Kind Regards
Massimo
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelpHibernate version: Mapping documents:Code between sessionFactory.openSession() and session.close():Full stack trace of any exception that occurs:Name and version of the database you are using:The generated SQL (show_sql=true):Debug level Hibernate log excerpt:[/code][url][/url]
Code: