Uploaded image for project: 'OpenJPA'
  1. OpenJPA
  2. OPENJPA-2319

Second (and following) execution of same JPQL is failed

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.2.1
    • None
    • sql
    • None
    • Debian testing
      OpenJDK Runtime Environment (IcedTea7 2.1.3) (7u3-2.1.3-1)
      Maven 3.0.4
      Groovy 2.0.5
      PostgreSQL 9.1-901-1.jdbc4
      Tomcat or Jetty web server

    Description

      Getting ReportingSQLException after second (and following) execution of JPQL. First execution (after server start) is normal.

      code
      ...
      public List<Payment> getPayments(IPayable participan) {
      	Query query = em.createQuery("select p from Payment p where (p.sender = ?1 or p.recipient = ?1) order by p.createDate desc");
      	query.setParameter(1, participan);
      	return (List<Payment>) query.getResultList();
      }
      ...
      
      log after first call of getPayments()
      33779  download-x  TRACE  [http-bio-8080-exec-10] openjpa.jdbc.SQL - <t 2028134790, conn 1685658195> executing prepstmnt 1156839632 
      SELECT t0.id, t0.dtype, t0.createdate, t0.description, 
              t0.recipient, t0.recipientaftercash, 
              t0.recipientbeforecash, t0.sender, 
              t0.senderaftercash, t0.senderbeforecash, t0.type, 
              t0.value, t0.download_id 
          FROM public.Payment t0 
          WHERE (t0.sender = ? OR t0.recipient = ?) 
          ORDER BY t0.createdate DESC 
      [params=(String) ru.bazon.downloadx.entities.security.User:51, (String) ru.bazon.downloadx.entities.security.User:51]
      33782  download-x  TRACE  [http-bio-8080-exec-10] openjpa.jdbc.SQL - <t 2028134790, conn 1685658195> [3 ms] spent
      
      log after second (and following) call of getPayments()
      165632  download-x  TRACE  [http-bio-8080-exec-10] openjpa.jdbc.SQL - <t 2028134790, conn 1685658195> executing prepstmnt 344249860 
      SELECT t0.id, t0.dtype, t0.createdate, t0.description, 
              t0.recipient, t0.recipientaftercash, 
              t0.recipientbeforecash, t0.sender, 
              t0.senderaftercash, t0.senderbeforecash, t0.type, 
              t0.value, t0.download_id 
          FROM public.Payment t0 
          WHERE (t0.sender = ? OR t0.recipient = ?) 
          ORDER BY t0.createdate DESC 
      [params=(int) 51, (int) 51]
      165635  download-x  TRACE  [http-bio-8080-exec-10] openjpa.jdbc.SQL - <t 2028134790, conn 1685658195> [3 ms] spent
      <openjpa-2.2.1-r422266:1396819 fatal general error> org.apache.openjpa.persistence.PersistenceException: ERROR: operator does not exist: character varying = integer
        HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
        Position: 243 {prepstmnt 344249860 
      SELECT t0.id, t0.dtype, t0.createdate, t0.description, 
              t0.recipient, t0.recipientaftercash, 
              t0.recipientbeforecash, t0.sender, 
              t0.senderaftercash, t0.senderbeforecash, t0.type, 
              t0.value, t0.download_id 
          FROM public.Payment t0 
          WHERE (t0.sender = ? OR t0.recipient = ?) 
          ORDER BY t0.createdate DESC 
      [params=(int) 51, (int) 51]} [code=0, state=42883]
      	at org.apache.openjpa.jdbc.sql.DBDictionary.narrow(DBDictionary.java:4958)
      	at org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:4918)
      	at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:136)
      	at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:110)
      	at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:62)
      	at org.apache.openjpa.jdbc.kernel.PreparedSQLStoreQuery$PreparedSQLExecutor.executeQuery(PreparedSQLStoreQuery.java:139)
      	at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:1005)
      	at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:863)
      	at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:794)
      	at org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:542)
      	at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:286)
      	at org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:302)
      	at javax.persistence.TypedQuery$getResultList.call(Unknown Source)
      	at ru.indvdum.jpa.dao.JPADataAccessObject.list(JPADataAccessObject.groovy:208)
      	at ru.bazon.downloadx.dao.DAO.getPayments(DAO.java:422)
      	at ru.bazon.downloadx.web.vaadin.main.mypayments.MyAllPaymentsComponent.redraw(MyAllPaymentsComponent.java:105)
      	at ru.bazon.downloadx.web.vaadin.main.MyPaymentsComponent.redraw(MyPaymentsComponent.java:47)
      	at ru.bazon.downloadx.web.vaadin.DownloadXComponent$3.selectedTabChange(DownloadXComponent.java:148)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:601)
      	at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:510)
      	at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:164)
      	at com.vaadin.ui.AbstractComponent.fireEvent(AbstractComponent.java:1219)
      	at com.vaadin.ui.TabSheet.fireSelectedTabChange(TabSheet.java:876)
      	at com.vaadin.ui.TabSheet.setSelectedTab(TabSheet.java:606)
      	at com.vaadin.ui.TabSheet.changeVariables(TabSheet.java:695)
      	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.changeVariables(AbstractCommunicationManager.java:1460)
      	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariableBurst(AbstractCommunicationManager.java:1404)
      	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariables(AbstractCommunicationManager.java:1329)
      	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:761)
      	at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(CommunicationManager.java:323)
      	at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:501)
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
      	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
      	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
      	at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
      	at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
      	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
      	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
      	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
      	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
      	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
      	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
      	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
      	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
      	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
      	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
      	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
      	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
      	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
      	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
      	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
      	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
      	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
      	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
      	at java.lang.Thread.run(Thread.java:722)
      Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: ERROR: operator does not exist: character varying = integer
        HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
        Position: 243 {prepstmnt 344249860 
      SELECT t0.id, t0.dtype, t0.createdate, t0.description, 
              t0.recipient, t0.recipientaftercash, 
              t0.recipientbeforecash, t0.sender, 
              t0.senderaftercash, t0.senderbeforecash, t0.type, 
              t0.value, t0.download_id 
          FROM public.Payment t0 
          WHERE (t0.sender = ? OR t0.recipient = ?) 
          ORDER BY t0.createdate DESC 
      [params=(int) 51, (int) 51]} [code=0, state=42883]
      	at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:219)
      	at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:203)
      	at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.access$700(LoggingConnectionDecorator.java:59)
      	at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingPreparedStatement.executeQuery(LoggingConnectionDecorator.java:1118)
      	at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:265)
      	at org.apache.openjpa.jdbc.sql.PostgresDictionary$PostgresPreparedStatement.executeQuery(PostgresDictionary.java:1019)
      	at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:265)
      	at org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement.executeQuery(JDBCStoreManager.java:1774)
      	at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:255)
      	at org.apache.openjpa.jdbc.kernel.PreparedSQLStoreQuery$PreparedSQLExecutor.executeQuery(PreparedSQLStoreQuery.java:118)
      	... 59 more
      NestedThrowables:
      org.postgresql.util.PSQLException: ERROR: operator does not exist: character varying = integer
        HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
        Position: 243
      	at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2103)
      	at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1836)
      	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
      	at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:512)
      	at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:388)
      	at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:273)
      	at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
      	at org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
      	at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:267)
      	at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingPreparedStatement.executeQuery(LoggingConnectionDecorator.java:1116)
      	at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:265)
      	at org.apache.openjpa.jdbc.sql.PostgresDictionary$PostgresPreparedStatement.executeQuery(PostgresDictionary.java:1019)
      	at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:265)
      	at org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement.executeQuery(JDBCStoreManager.java:1774)
      	at org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:255)
      	at org.apache.openjpa.jdbc.kernel.PreparedSQLStoreQuery$PreparedSQLExecutor.executeQuery(PreparedSQLStoreQuery.java:118)
      	at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:1005)
      	at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:863)
      	at org.apache.openjpa.kernel.QueryImpl.execute(QueryImpl.java:794)
      	at org.apache.openjpa.kernel.DelegatingQuery.execute(DelegatingQuery.java:542)
      	at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:286)
      	at org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:302)
      	at javax.persistence.TypedQuery$getResultList.call(Unknown Source)
      	at ru.indvdum.jpa.dao.JPADataAccessObject.list(JPADataAccessObject.groovy:208)
      	at ru.bazon.downloadx.dao.DAO.getPayments(DAO.java:422)
      	at ru.bazon.downloadx.web.vaadin.main.mypayments.MyAllPaymentsComponent.redraw(MyAllPaymentsComponent.java:105)
      	at ru.bazon.downloadx.web.vaadin.main.MyPaymentsComponent.redraw(MyPaymentsComponent.java:47)
      	at ru.bazon.downloadx.web.vaadin.DownloadXComponent$3.selectedTabChange(DownloadXComponent.java:148)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:601)
      	at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:510)
      	at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:164)
      	at com.vaadin.ui.AbstractComponent.fireEvent(AbstractComponent.java:1219)
      	at com.vaadin.ui.TabSheet.fireSelectedTabChange(TabSheet.java:876)
      	at com.vaadin.ui.TabSheet.setSelectedTab(TabSheet.java:606)
      	at com.vaadin.ui.TabSheet.changeVariables(TabSheet.java:695)
      	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.changeVariables(AbstractCommunicationManager.java:1460)
      	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariableBurst(AbstractCommunicationManager.java:1404)
      	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariables(AbstractCommunicationManager.java:1329)
      	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:761)
      	at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(CommunicationManager.java:323)
      	at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:501)
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
      	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
      	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
      	at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
      	at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
      	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
      	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
      	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
      	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
      	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
      	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
      	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
      	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
      	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
      	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
      	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
      	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
      	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
      	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
      	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
      	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
      	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
      	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
      	at java.lang.Thread.run(Thread.java:722)
      
      persistence.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
      	<persistence-unit name="download-x">
      		<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
      		<non-jta-data-source>java:comp/env/jdbc/download-x</non-jta-data-source>
      
      		<class&gt;ru.bazon.downloadx.entities.links.Download</class&gt;
      		<class&gt;ru.bazon.downloadx.entities.links.Link</class&gt;
      		<class&gt;ru.bazon.downloadx.entities.pay.DownloadPayment</class&gt;
      		<class&gt;ru.bazon.downloadx.entities.pay.Payment</class&gt;
      		<class&gt;ru.bazon.downloadx.entities.security.Role</class&gt;
      		<class&gt;ru.bazon.downloadx.entities.security.User</class&gt;
      		<class&gt;ru.bazon.downloadx.entities.settings.SystemSettings</class&gt;
      		<class&gt;ru.bazon.downloadx.entities.settings.WebMoneySettings</class&gt;
      
      		<properties>
      			<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
      			<property name="openjpa.Multithreaded" value="true"/>
      			<property name="openjpa.jdbc.SchemaFactory" value="native(ForeignKeys=true)"/>
      			<property name="openjpa.jdbc.EagerFetchMode" value="none"/>
      			<property name="openjpa.ConnectionFactoryProperties" value="PrintParameters=true, PrettyPrint=true"/>
      			<property name="openjpa.DetachState" value="all"/>
      			<property name="openjpa.RuntimeUnenhancedClasses" value="unsupported"/>
      			<property name="openjpa.InverseManager" value="true(Action=warn)"/>
      		</properties>
      	</persistence-unit>
      </persistence>
      
      Payment.groovy
      package ru.bazon.downloadx.entities.pay
      
      import javax.persistence.CascadeType
      import javax.persistence.Entity
      import javax.persistence.EnumType
      import javax.persistence.Enumerated
      import javax.persistence.GeneratedValue
      import javax.persistence.Id
      import javax.persistence.ManyToOne
      
      import ru.bazon.downloadx.pay.PaymentType
      import ru.indvdum.jpa.entities.AbstractEntity
      
      @Entity
      class Payment extends AbstractEntity {
      
      	@Id
      	@GeneratedValue
      	int id;
      
      	BigDecimal value = BigDecimal.ZERO;
      	BigDecimal senderBeforeCash = 0;
      	BigDecimal senderAfterCash = 0;
      	BigDecimal recipientBeforeCash = 0;
      	BigDecimal recipientAfterCash = 0;
      	String description;
      	Date createDate;
      
      	@Enumerated(EnumType.STRING)
      	PaymentType type = PaymentType.Transfer;
      
      	@ManyToOne(cascade = [CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH])
      	IPayable sender;
      
      	@ManyToOne(cascade = [CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH])
      	IPayable recipient;
      	
      	@Override
      	public String toString() {
      		return "${value}";
      	}
      }
      
      IPayable.java
      package ru.bazon.downloadx.entities.pay;
      
      import java.math.BigDecimal;
      
      public interface IPayable {
      
      	BigDecimal getCash();
      
      	void setCash(BigDecimal cash);
      
      }
      
      User.groovy
      package ru.bazon.downloadx.entities.security
      
      import javax.persistence.CascadeType
      import javax.persistence.Entity
      import javax.persistence.FetchType
      import javax.persistence.GeneratedValue
      import javax.persistence.Id
      import javax.persistence.ManyToMany
      import javax.persistence.OneToMany
      import javax.persistence.Table
      import javax.persistence.Temporal
      import javax.persistence.TemporalType
      import javax.persistence.Transient
      
      import org.apache.openjpa.persistence.jdbc.Unique
      import org.apache.shiro.authc.AuthenticationInfo
      import org.apache.shiro.authc.SaltedAuthenticationInfo
      import org.apache.shiro.authz.AuthorizationInfo
      import org.apache.shiro.crypto.hash.Sha256Hash
      import org.apache.shiro.subject.PrincipalCollection
      import org.apache.shiro.subject.SimplePrincipalCollection
      import org.apache.shiro.util.ByteSource
      import org.apache.shiro.util.SimpleByteSource
      
      import ru.bazon.downloadx.entities.links.Link
      import ru.bazon.downloadx.entities.pay.IPayable
      import ru.bazon.downloadx.security.Permit
      import ru.indvdum.jpa.entities.AbstractEntity
      
      @Entity
      @Table(name = "users")
      class User extends AbstractEntity implements IPayable, AuthorizationInfo, AuthenticationInfo, SaltedAuthenticationInfo {
      
      	@Id
      	@GeneratedValue
      	int id;
      
      	@Unique
      	String login;
      	
      	String passwordHash;
      	String firstName;
      	String middleName;
      	String lastName;
      	String email;
      	String phone;
      	// TODO: reserve cash for link payments
      	BigDecimal cash = BigDecimal.ZERO;
      	Date registerDate;
      	Date repeatedDownloadsDate;
      
      	@Temporal(TemporalType.DATE)
      	Date birthDate;
      
      	@ManyToMany(fetch = FetchType.EAGER, cascade = [CascadeType.DETACH, CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH])
      	Set<Role> userRoles = new HashSet<Role>();
      
      	@OneToMany(mappedBy = "user", orphanRemoval = true, fetch = FetchType.EAGER, cascade = CascadeType.ALL)
      	Set<Link> links = new HashSet<Link>();
      
      	public String getName() {
      		return "${firstName} ${middleName} ${lastName}";
      	}
      
      	public String setPassword(String password) {
      		Sha256Hash sha256Hash = new Sha256Hash(password, callMethod("getCredentialsSalt").getBytes());
      		passwordHash = sha256Hash.toHex();
      		return passwordHash;
      	}
      
      	@Transient
      	private String realmName;
      
      	public void setRealmName(String realmName) {
      		this.realmName = realmName;
      	}
      
      	@Override
      	public PrincipalCollection getPrincipals() {
      		return new SimplePrincipalCollection(id, realmName);
      	}
      
      	@Override
      	public Object getCredentials() {
      		return passwordHash;
      	}
      
      	@Override
      	public Collection<String> getStringPermissions() {
      		Set<String> permissionsNames = new HashSet<String>();
      		for (Role role : userRoles) {
      			for (Permit permit : role.getPermits()) {
      				permissionsNames.add(permit.getName());
      			}
      		}
      		return permissionsNames;
      	}
      
      	@Override
      	public Collection<Permit> getObjectPermissions() {
      		Set<Permit> permissions = new HashSet<Permit>();
      		for (Role role : userRoles) {
      			for (Permit permit : role.getPermits()) {
      				permissions.add(permit);
      			}
      		}
      		return permissions;
      	}
      
      	@Override
      	public ByteSource getCredentialsSalt() {
      		return new SimpleByteSource("random_salt_value_" + login);
      	}
      
      	@Override
      	public Collection<String> getRoles() {
      		Collection<String> roles = new HashSet<String>();
      		for (Role role : userRoles) {
      			roles.add(role.getName());
      		}
      		return roles;
      	}
      
      	public boolean isPermitted(Permit permission) {
      		for (Role role : userRoles) {
      			if (role.isPermitted(permission))
      				return true;
      		}
      		return false;
      	}
      
      	@Override
      	public String toString() {
      		return "${login}";
      	}
      }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            indvdum indvdum
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: