This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
public class EmployeeManager { static Employee empObj=null; static Machine mac = null; /******************************************************/ public static void main(String[] args) { EmployeeManager mgr = new EmployeeManager();
if (args[0].equals("storeMac")) { mgr.createAndStoreMac(args[1],args[2]); System.out.println("mac data stored..."); } else if (args[0].equals("storeEmp")) { String macid=mgr.createAndStoreMac(args[1],args[2]); mgr.createAndStoreEmp(args[3],args[4],Integer.parseInt(args[5]),macid); } /******************************************************/ private Long createAndStoreEmp(String name, String city, int salary, String macId) { System.out.println("in emp..."); Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction();
When I tried to run the above code I'm getting following exception -
in store mac... log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment). log4j:WARN Please initialize the log4j system properly. Initial SessionFactory creation failed.org.hibernate.MappingException: Could not read mappings from resource: emp/Employee.hbm.xml Exception in thread "main" java.lang.ExceptionInInitializerError at util.HibernateUtil.<clinit>(HibernateUtil.java:17) at emp.EmployeeManager.createAndStoreMac(EmployeeManager.java:110) at emp.EmployeeManager.main(EmployeeManager.java:19) Caused by: org.hibernate.MappingException: Could not read mappings from resource: emp/Employee.hbm.xml at org.hibernate.cfg.Configuration.addResource(Configuration.java:484) at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1453) at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1421) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1402) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1378) at org.hibernate.cfg.Configuration.configure(Configuration.java:1298) at org.hibernate.cfg.Configuration.configure(Configuration.java:1284) at util.HibernateUtil.<clinit>(HibernateUtil.java:13) ... 2 more Caused by: org.hibernate.MappingException: invalid mapping at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:424) at org.hibernate.cfg.Configuration.addResource(Configuration.java:481) ... 9 more Caused by: org.xml.sax.SAXParseException: Attribute "column" must be declared for element type "one-to-one". at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source) at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) at org.apache.xerces.impl.dtd.XMLDTDValidator.addDTDDefaultAttrsAndValidate(Unknown Source) at org.apache.xerces.impl.dtd.XMLDTDValidator.handleStartElement(Unknown Source) at org.apache.xerces.impl.dtd.XMLDTDValidator.emptyElement(Unknown Source) at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source) at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source) at org.dom4j.io.SAXReader.read(SAXReader.java:465) at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:421) ... 10 more
Please let me know what might be the reason behind it.
Thanks for your time.
Nilesh
Nilesh<br />SCJP<br />IBM certified for OOAD using UML
There is a CODE button in the 10 buttons below Add Post/Reply. Please use this button to post your code, so that all indentation is kept. When you post code/xml without indentation, we just can't read it.
Anyway, luckily we don't have to read it.
"Caused by: org.hibernate.MappingException: invalid mapping at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:424) at org.hibernate.cfg.Configuration.addResource(Configuration.java:481) ... 9 more Caused by: org.xml.sax.SAXParseException: Attribute "column" must be declared for element type "one-to-one"."
so for your one-to-one mapping in the Employee.hbm.xml is missing the "column" portion of that mapping.
OK, so maybe you do need to repost your code. Because if it isn't indented then I can't read it, that is why I didn't even look, to difficult to find stuff.
OK, so it looks like you are having a one-to-one unidirectional association. In the Hibernate docs, it has you use a many-to-one with a "unique" attribute