Hibernate mapping for one-to-one?

Worked out answer in the comments, evidently....

Up vote 0 down vote favorite share g+ share fb share tw.

I have two classes binded mapped with Hibernate and I can't figure out the configuration to map a Drug entry to my PrescribedDrug class. Public class PrescribedDrug implements Serializable { protected int prescribedDrugId; private int drugId; protected String sig; protected int quantity; protected int refillNumber; protected Drug drugInfo; ... } public class Drug implements Serializable { protected int drugId; protected String name; protected double strength; protected String strengthUnits; ... } My data model looks like this: prescribed_drug drug ---------- -------------- prescribed_drug_id* drug_id* drug_id* name sig .... ... Here is my hibernate configuration: NOTE here that I tried to map my Drug in the PrescribedDrug.hbm. Xml config using a one-to-one but hibernate keeps telling me to add the fields of Drug to the PrescribedDrug file... field name not found on org.example.smartgwt.shared.model.

PrescribedDrug Entries in drug table are a static and contains the properties of the prescribed drugs. Thank you. Java hibernate mapping link|improve this question asked Jul 23 '10 at 22:49code-gijoe1,010216 89% accept rate.

What I don't get is this private int drugId; in the PrescribedDrug class. – Pascal Thivent Jul 24 '10 at 0:39 Should not be there... I added it because of Hibernate. But I removed it in my final version.

I had a few mistakes in my mapping, fixed thanks to @hvgotcodes. – code-gijoe Jul 24 '10 at 12:26.

Yeah, it wasn't there at the beginning, than Hibernate told me to add it. So I did. Than it told me to add "name" which is another field in the Drug class.

– code-gijoe Jul 23 '10 at 22:57 How else can Hibernate know that to which drug_id I'm relating the prescription? – code-gijoe Jul 23 '10 at 23:02 @code-gijoe you can use a unique many-to-one, as layed out here.... docs.jboss.org/hibernate/core/3.3/refere... – hvgotcodes Jul 23 '10 at 23:05 Actually 1 prescribed drug has a single drug id. But a drug can be related to multiple prescriptions.

– code-gijoe Jul 23 '10 at 23:05 @code-gijoe, if you use a one-to-one, the keys of the two classes have to be the same. I think your situation is more appropriate for a constrained many to one. – hvgotcodes Jul 23 '10 at 23:11.

In your mappings, I saw you only mapped for PrescribedDrug. Change your 2nd mapping file class to Drug.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions