所以我已经在谷歌和stack上搜索过了,我找到了一堆有同样错误的人,但是没有一个解决方案能解决我的问题。
我正在使用的:
我认为问题在于命名查询,也许还有ManyToMany关系。
User.java
@Entity
@Table(name ="system_user")
public class User {
@Id
@Column
private int id;
@Column
private String login;
@Column
private String password;
@ManyToMany
@JoinTable(
name="user_role_relation",
joinColumns=@JoinColumn(name="user_id", referencedColumnName="id"),
inverseJoinColumns=@JoinColumn(name="role_id", referencedColumnName="id"))
private List<SystemRole> rolesRelation;
@Transient
private List<Role> roles;
public User(){}
public List<Role> getRoles(){
if(this.roles == null){
List<Role> roles = new ArrayList<>();
for(SystemRole relation : rolesRelation){
roles.add(relation.getCode());
}
this.roles = roles;
}
return new ArrayList<>(this.roles);
}
public String getLogin(){
return this.login;
}
public String getPassword(){
return this.password;
}
}
SystemRole.java
@Entity
@Table(name="system_role")
public class SystemRole{
@Id
private int id;
@Column
private String name;
@Column
@Enumerated(EnumType.STRING)
private Role code;
@ManyToMany(mappedBy="rolesRelation")
private List<User> users;
public SystemRole(){}
Role getCode(){
return this.code;
}
public static enum Role {
MANAGER, EXECUTIVE, HRBP, ADMIN, USER;
}
}
持久性.xml
<?xml version="1.0" encoding="UTF-8" ?>
<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_2_0.xsd"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="Pulse-PU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>java:global/jdbc/postgresds</jta-data-source>
<mapping-file>META-INF/user-orm.xml</mapping-file>
<class>com.appus.pulse.jaas.entity.SystemRole</class>
<class>com.appus.pulse.jaas.entity.User</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
<property name="javax.persistence.jdbc.show_sql" value="true" />
<property name="eclipselink.logging.level" value="ALL" />
</properties>
</persistence-unit>
</persistence>
user-orm.xml
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_1_0.xsd"
version="1.0">
<named-query name="User.getByLogin">
<query>
SELECT
user
FROM User user
JOIN FETCH user.rolesRelation rr
WHERE user.login = :login
</query>
</named-query>
</entity-mappings>
context.xml
<Context>
<Resource name="jdbc/postgresds"
auth="Container"
type="javax.sql.DataSource"
initialSize="5"
maxActive="55"
maxIdle="21"
minIdle="3"
timeBetweenEvictionRunsMillis="34000"
minEvictableIdleTimeMillis="55000"
validationQuery="SELECT 1"
validationInterval="34"
testOnBorrow="true"
removeAbandoned="true"
removeAbandonedTimeout="233"
driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5432/pulse"
username="postgres"
password=""/>
</Context>
我用于返回User的示例代码
TestResource.java
@Path("/user-test")
@Produces("plain/text")
@RequestScoped
public class TestResource {
@EJB(beanName="userdao")
private UserRepository userRepository;
@GET
public void getTest(){
userRepository.getByLogin("admin");
System.out.println("teste");
}
}
用户存储库.java
@Local
public interface UserRepository {
public User getByLogin(String login);
}
用户DAO.java
@Stateless(name="userdao")
public class UserDAO implements UserRepository{
@PersistenceContext(unitName = "Pulse-PU")
private EntityManager entityManager;
public User getByLogin(String login) {
return entityManager.createNamedQuery("User.getByLogin", User.class)
.setParameter("login", login)
.getSingleResult();
}
}
最后是一个例外
Internal Exception: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: SYSTEM_ROLE
Error Code: -5501
Call: SELECT t1.ID, t1.LOGIN, t1.PASSWORD, t0.ID, t0.CODE, t0.NAME FROM system_role t0, user_role_relation t2, system_user t1 WHERE ((t1.LOGIN = ?) AND ((t2.user_id = t1.ID) AND (t0.ID = t2.role_id)))
bind => [admin]
Query: ReadAllQuery(name="User.getByLogin" referenceClass=User sql="SELECT t1.ID, t1.LOGIN, t1.PASSWORD, t0.ID, t0.CODE, t0.NAME FROM system_role t0, user_role_relation t2, system_user t1 WHERE ((t1.LOGIN = ?) AND ((t2.user_id = t1.ID) AND (t0.ID = t2.role_id)))")
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:340)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:684)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:560)
at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:2055)
at org.eclipse.persistence.sessions.server.ServerSession.executeCall(ServerSession.java:570)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:242)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:228)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:299)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:694)
at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:2740)
at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRows(ExpressionQueryMechanism.java:2693)
at org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:559)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1175)
at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:904)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1134)
at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:460)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1222)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2896)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1857)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1839)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1804)
at org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery(QueryImpl.java:258)
at org.eclipse.persistence.internal.jpa.QueryImpl.getSingleResult(QueryImpl.java:521)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getSingleResult(EJBQueryImpl.java:400)
at com.appus.pulse.dao.UserDAO.getByLogin(UserDAO.java:20)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:205)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:186)
at org.apache.openejb.monitoring.StatsInterceptor.record(StatsInterceptor.java:181)
at org.apache.openejb.monitoring.StatsInterceptor.invoke(StatsInterceptor.java:100)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:205)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:186)
at org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:85)
at org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:236)
at org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:203)
at org.apache.openejb.core.ivm.EjbObjectProxyHandler.synchronizedBusinessMethod(EjbObjectProxyHandler.java:265)
at org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:260)
at org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:89)
at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:347)
at com.sun.proxy.$Proxy113.getByLogin(Unknown Source)
at com.appus.pulse.ws.TestResource.getTest(TestResource.java:21)
at com.appus.pulse.ws.TestResource$$OwbNormalScopeProxy0.getTest(com/appus/pulse/ws/TestResource.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.openejb.server.cxf.rs.PojoInvoker.performInvocation(PojoInvoker.java:43)
at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96)
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:189)
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:99)
at org.apache.openejb.server.cxf.rs.AutoJAXRSInvoker.invoke(AutoJAXRSInvoker.java:68)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:96)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:253)
at org.apache.openejb.server.cxf.rs.CxfRsHttpListener.doInvoke(CxfRsHttpListener.java:237)
at org.apache.tomee.webservices.CXFJAXRSFilter.doFilter(CXFJAXRSFilter.java:94)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.openejb.server.httpd.WebBeansFilter.doFilter(WebBeansFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:522)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1095)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.sql.SQLSyntaxErrorException: user lacks privilege or object not found: SYSTEM_ROLE
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCPreparedStatement.<init>(Unknown Source)
at org.hsqldb.jdbc.JDBCConnection.prepareStatement(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tomcat.jdbc.pool.ProxyConnection.invoke(ProxyConnection.java:126)
at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:108)
at org.apache.tomcat.jdbc.pool.DisposableConnectionFacade.invoke(DisposableConnectionFacade.java:81)
at com.sun.proxy.$Proxy114.prepareStatement(Unknown Source)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.prepareStatement(DatabaseAccessor.java:1565)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.prepareStatement(DatabaseAccessor.java:1514)
at org.eclipse.persistence.internal.databaseaccess.DatabaseCall.prepareStatement(DatabaseCall.java:778)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:621)
... 88 more
Caused by: org.hsqldb.HsqlException: user lacks privilege or object not found: SYSTEM_ROLE
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.SchemaManager.getTable(Unknown Source)
at org.hsqldb.ParserDQL.readTableName(Unknown Source)
at org.hsqldb.ParserDQL.readTableOrSubquery(Unknown Source)
at org.hsqldb.ParserDQL.XreadTableReference(Unknown Source)
at org.hsqldb.ParserDQL.XreadFromClause(Unknown Source)
at org.hsqldb.ParserDQL.XreadTableExpression(Unknown Source)
at org.hsqldb.ParserDQL.XreadQuerySpecification(Unknown Source)
at org.hsqldb.ParserDQL.XreadSimpleTable(Unknown Source)
at org.hsqldb.ParserDQL.XreadQueryPrimary(Unknown Source)
at org.hsqldb.ParserDQL.XreadQueryTerm(Unknown Source)
at org.hsqldb.ParserDQL.XreadQueryExpressionBody(Unknown Source)
at org.hsqldb.ParserDQL.XreadQueryExpression(Unknown Source)
at org.hsqldb.ParserDQL.compileCursorSpecification(Unknown Source)
at org.hsqldb.ParserCommand.compilePart(Unknown Source)
at org.hsqldb.ParserCommand.compileStatement(Unknown Source)
at org.hsqldb.Session.compileStatement(Unknown Source)
at org.hsqldb.StatementManager.compile(Unknown Source)
at org.hsqldb.Session.execute(Unknown Source)
... 102 more
很抱歉发布了这么长的帖子,但是我想把每一段重要的代码都放进去。所以如果有任何信息遗漏了,请告诉我。我真的不知道是什么问题,我以为问题是没有公共setter,但据我所知,JPA不需要使用setter。
所以,我已经解决了这个问题,这是一个配置问题。我注意到在持久性中.xml它指向java:全局/jdbc/postgresds,并且我在上下文中定义了资源.xml该资源位于应用程序目录的META-INF中。资源的名称是 jdbc/postgresds,所以我只是在 jta 数据源中删除了全局,并且必须在资源 JtaManaged=“true” 中添加。
现在一切都很好。
感谢所有评论这篇文章的人。
我遵循了以下基本的Spring批量教程https://spring.io/guides/gs/batch-processing/ . > 我正在使用IntelliJ 14并创建了一个Spring批处理项目 我在用Mavin。我还有pom。xml文件。 Mvn clean install运行良好,即使应用程序。java告诉我“无法自动连线。找不到JdbcTemplate类型的bean”@Autowi
我在hsqldb测试中遇到了一点问题。 我在import.sql中添加了我需要的所有内容,它工作得很好。 我创建了一个类: 但是我得到了这个错误:
我发现这个错误在整个互联网上出现了很多次,但我根本没有找到适合我的情况的解决方案。我有一个 HSQL 数据库 - 我已成功连接到数据库中的一个表。我继续在数据库中创建另一个表 - 根据需要修改完全相同的 Java 代码,但它带来了错误:java.sql.SQLSyntaxErrorException:用户缺少权限或找不到对象:USER。 我发现在我的文件存储脚本中,PRODUCT表创建的代码就在那
我正在尝试做一些Ucanaccess实践,用Java管理一些数据库。我得到了一个我不知道如何解决的错误。 我在Access中有一个名为USERS的表: 自动编号,短文本,短文本,数字。 代码继续,但只有一些条件和查询。
当我试图将数据放入数据库时,我出现了一个错误,这是我的注册函数