Hibernate One-To-Many and Many-to-One mapping -
I know that this topic has already been discussed. But I still have problems. I have two tables - Thanks I am explaining the scenario The person model will be like a hibernate mapping The hybrid mapping will be done for the Account model Both models (POOs) such as Now the important thing is that with the help of hibernate in the above structure you can save a single person alone in the database Screen-1 accepts the information of the person And saves it in the database screen-2 Accepts information from more than one account with the above person And saves it in the database. But the important thing is that you have to maintain person ID ie per ID in hidden areas so that you really know how its account is. Without the person here, the account object will not be saved in the database. This means that the account one-to-many relationship is tightly coupled with the help of the person with the help of the hibernate and the foreign key will be automatically created by the hibernate in the account table as perID . person and
account . The
PERSON_ID person is the primary key in the table and the child is the foreign key in the table accounts. There is a screen on my web app that helps to maintain the
person table . Now on the second
screen-account , I'm facing a problem with mapping. I believe that I have the right annotation in my parents and child classes. But when I try to insert a new
account to
person_id then the second screen is inserted into "table" in the form of a "tap" followed by An update statement is removed on the same account table. Make sure why these two problems are happening.
account * ---
& lt; Hibernate-mapping package = "model" & gt; & Lt; Class name = "account" table = "HIB_ACC" & gt; & Lt; Id name = "accID" column = "ACC_ID" & gt; & Lt; Generator class = "original" & gt; & Lt; / Generator & gt; & Lt; / Id & gt; & Lt; Many-to-one names = "person" class = "person" column = "PER_ID" lazy = "no-proxy" fetch = "select" /> & Lt; / Square & gt; & Lt; / Hibernate-mapping & gt;
class person {personal int perID; Private set & lt; Account & gt; Accounts; // gates and setters} class account {personal INC accID; Private person; // getters and setters}
person p = new person (); // Set your seters // save db session.save (p)
Person page = Get the database from the PerID account with acc1 = new account (); // Set / Set Your Setters // Set acc1.setPerson (p) to your boss; Account acc2 = new account (); // Set up your setters // Set AC 2 to your boss.Setpronson (P); // save in the DB session save (acc1) session.save (acc2)
Comments
Post a Comment