Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple classes in PersistenceUnit
    primarykey
    data
    text
    <p>I have a project which uses another project as a lib and I have Spring and Hibernate on both projects, the problem is that I need to map the classes from my first project to my second project.</p> <p>This is the exception I got:</p> <pre><code>Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: Usuario is not mapped [SELECT u FROM Usuario u WHERE usuario = 'abc' order by idUsuario desc] at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:180) </code></pre> <p>So I tried to map the classes in the persistence.xml, this way:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"&gt; &lt;persistence-unit name="default"&gt; &lt;class&gt;com.planner.pov.model.Usuario&lt;/class&gt; &lt;class&gt;com.planner.pov.model.LogWork&lt;/class&gt; &lt;class&gt;com.planner.pov.model.Responsavel&lt;/class&gt; &lt;class&gt;com.planner.pov.model.GrupoResponsavel&lt;/class&gt; &lt;class&gt;com.planner.pov.model.Cargo&lt;/class&gt; &lt;class&gt;com.planner.pov.model.TarefaBackLog&lt;/class&gt; &lt;class&gt;com.planner.pov.model.ItemBackLog&lt;/class&gt; &lt;/persistence-unit&gt; </code></pre> <p></p> <p>But there are so many classes to map, they are all chained... Is there a better way to do it?</p> <p>@EDIT</p> <p>applicationContext.xml</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"&gt; &lt;context:component-scan base-package="com.planner.pov" /&gt; &lt;bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /&gt; &lt;bean id="ConfiguradorDePropriedades" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt; &lt;description&gt;The service properties file&lt;/description&gt; &lt;property name="location" value="file:AppConfig.properties" /&gt; &lt;/bean&gt; &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt; &lt;property name="dataSource" ref="dataSourceLocal" /&gt; &lt;property name="packagesToScan" value="com.planner.pov" /&gt; &lt;property name="jpaVendorAdapter"&gt; &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt; &lt;property name="database" value="${database}" /&gt; &lt;property name="showSql" value="false" /&gt; &lt;property name="generateDdl" value="true" /&gt; &lt;/bean&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="dataSourceLocal" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt; &lt;property name="driverClassName" value="${driver}" /&gt; &lt;property name="url" value="${jdbc.url}" /&gt; &lt;property name="username" value="${jdbc.user}" /&gt; &lt;property name="password" value="${jdbc.pass}" /&gt; &lt;/bean&gt; &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt; &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt; &lt;/bean&gt; &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt; &lt;!-- Configuração do LogWorkController --&gt; &lt;bean id="logWorkDao" class="br.javablocker.dao.LogWorkDaoImpl" /&gt; &lt;!-- Configuração do ClockMainController --&gt; &lt;bean id="clockMainController" class="br.javablocker.controller.PlannerClockMainController"&gt; &lt;property name="usuarioController" ref="usuarioController" /&gt; &lt;property name="logWorkDao" ref="logWorkDao" /&gt; &lt;/bean&gt; &lt;!-- Configuração do UsuarioController --&gt; &lt;bean id="usuarioDao" class="br.javablocker.dao.UsuarioDaoImpl" /&gt; &lt;bean id="responsavelDao" class="com.planner.pov.dao.ResponsavelDaoImpl" /&gt; &lt;bean id="usuarioController" class="br.javablocker.controller.UsuarioController"&gt; &lt;property name="usuarioDao" ref="usuarioDao" /&gt; &lt;property name="responsavelDao" ref="responsavelDao" /&gt; &lt;property name="logWorkDao" ref="logWorkDao" /&gt; &lt;/bean&gt; &lt;bean id="logWorkController" class="br.javablocker.controller.LogWorkController"&gt; &lt;property name="logWorkDao" ref="logWorkDao" /&gt; &lt;/bean&gt; &lt;/beans&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload