Questions Tagged With jpahttps://answers.axonivy.com/tags/jpa/?type=rssquestions tagged <span class="tag">jpa</span>enThu, 26 May 2016 16:59:17 -0400How can i persist a file as BLOB?https://answers.axonivy.com/questions/1779/how-can-i-persist-a-file-as-blob<p>Hi,</p> <p>i am using the primefaces fileupload widget, so users can upload attatchment files. right now, i save the files on the filesystem and i persist the path to the file in the database.</p> <p>is there a way to save files as BLOB in relational database?</p> <p>Thank you for your answers!</p>joha0123Thu, 26 May 2016 16:59:17 -0400https://answers.axonivy.com/questions/1779/how-can-i-persist-a-file-as-blobjpafileivypersistenceAvoid MultipleBagFetchException when referencing multiple collections of another typehttps://answers.axonivy.com/questions/1745/avoid-multiplebagfetchexception-when-referencing-multiple-collections-of-another-type<p>I know how to store a single list in a JPA class. but now everytime i try to add another list to any other entity class i get an ivy:error:persistence, with following error message:</p> <pre><code>IvyScriptRuntimeException: IvyScript Runtime Exception in Instruction: ivy.persistence.axsosUnit.findAll(teamprojekt.Job.class) Block: teamprojekt.showDashboard.showDashboardData out; out = in; in.data.closedJobs = ivy.persistence.axsosUnit.findAll(teamprojekt.Job.class); IvyScriptMethodInvocationException: Error calling method findAll(java.lang.Class) on an object of class ch.ivyteam.ivy.process.data.persistence.internal.IvyEntityManager. PersistenceUnitException: Failed to excecute operation "findAll" for persistence unit "axsosUnit". PersistenceUnitException: Could not create EntityManagerFactory of persistence unit'axsosUnit' PersistenceException: [PersistenceUnit: axsosUnit] Unable to build EntityManagerFactory MultipleBagFetchException: cannot simultaneously fetch multiple bags </code></pre> <p>I have read, that you cant use two lists in the same entity class, but i use them in different entity classes. maybe because they are nested?</p> <p>the structure is: institutionList is inside education which is inside application which has the other list.</p> <p>I have also read, the solution is to use a set instead of a list. can you explain how to do this? I've tried to change the list to a set from the entity class wizzard, but without success.</p> <p>can you show me how to do this?</p> <p>thank you very much</p>joha0123Fri, 22 Apr 2016 22:04:56 -0400https://answers.axonivy.com/questions/1745/avoid-multiplebagfetchexception-when-referencing-multiple-collections-of-another-typejpadataclasspersistenceHow can I add a List to a databasehttps://answers.axonivy.com/questions/1740/how-can-i-add-a-list-to-a-database<p>I am filling a List and then I try to write it to the database. We have two Entity Classes: Application and Education. The relationship is 1:N. (One application can have many educations)</p> <p>In the Application entity class I have created a List of Education with the relationship ONE_TO_MANY. Mapped by attribute is <strong>appl</strong>. In the Education entity class i have created a field <strong>appl</strong> with the relationship MANY_TO_ONE.</p> <p>The Problem is, that i have to initialize all objects before i can write data into them. this is impossible to do, because the application Object has a Education object in it and the Education Object has a Application object in it.</p> <p>Is there an other way to save my data to a database?</p> <p>thanks.</p>joha0123Wed, 20 Apr 2016 16:25:00 -0400https://answers.axonivy.com/questions/1740/how-can-i-add-a-list-to-a-databasejpadataclassivypersistenceHow to use JPA entity manager instead of Ivy Entity Manager?https://answers.axonivy.com/questions/1102/how-to-use-jpa-entity-manager-instead-of-ivy-entity-manager<p>Hi everyone,</p> <p>Currently, I need to set up and use the JPA entity manager not Ivy Entity Manager because our team want it to work with JUnit. (Ivy Entity Manager doesn't work with JUnit because of Ivy environment).</p> <p>Is that possible to do so? I have tried edit the persistence.xml and try to create an entity manager but I've got the exception:</p> <pre><code>javax.persistence.PersistenceException: [PersistenceUnit: xrfl_unit] Unable to build EntityManagerFactory at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:924) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:899) at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:59) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47) at ch.soreco.standard.xrfl.service.TransactionManager.execute(TransactionManager.java:38) at ch.soreco.standard.xrfl.service.ValuationService.findAll(ValuationService.java:26) at ch.soreco.standard.xrfl.unittest.service.ValuationServiceTest.findAll(ValuationServiceTest.java:28) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) at org.junit.runners.ParentRunner.run(ParentRunner.java:300) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Caused by: org.hibernate.service.jndi.JndiException: Error parsing JNDI name [XRFL] at org.hibernate.service.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:92) at org.hibernate.service.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:63) at org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl.configure(DatasourceConnectionProviderImpl.java:116) at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:85) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:184) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:156) at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:223) at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:89) at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:85) at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:184) at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:156) at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1825) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1783) at org.hibernate.ejb.EntityManagerFactoryImpl.&lt;init&gt;(EntityManagerFactoryImpl.java:96) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914) ... 31 more Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial at javax.naming.spi.NamingManager.getInitialContext(Unknown Source) at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source) at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source) at javax.naming.InitialContext.getNameParser(Unknown Source) at org.hibernate.service.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:86) ... 45 more </code></pre> <p>If you have any idea or suggestion, please share with me.</p> <p>Thank You.</p>Tran Cuong TrucMon, 22 Dec 2014 03:47:09 -0500https://answers.axonivy.com/questions/1102/how-to-use-jpa-entity-manager-instead-of-ivy-entity-managerjpaunit-testhibernateIs it possible to create entity classes from an existing database?https://answers.axonivy.com/questions/217/is-it-possible-to-create-entity-classes-from-an-existing-database<p>I'm wondering if it is possible to derive Data Entity Classes from an existing database. So to take it the other way around - not generating the database schema from the entity classes but the entity classes from a database. Is that somehow possible?</p>Nikel WeisThu, 19 Dec 2013 11:49:24 -0500https://answers.axonivy.com/questions/217/is-it-possible-to-create-entity-classes-from-an-existing-databasejpa