Mantis Bugtracker
  

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0002037 [Resin] major always 10-03-07 09:15 11-07-07 15:18
Reporter westrupp View Status public  
Assigned To ferg
Priority normal Resolution fixed  
Status closed   Product Version 3.1.3
Summary 0002037: amber embedded compound pk with many-to-one generates wrong sql
Description I have 3 Entity beans:

@Entity(name = "User")
@Table(name = "APP_USERS")
public class User {
    private Integer userId;
    private String userName;
    @Id
    @Column(name = "USER_ID", nullable = false, length = 22)
    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    @Basic
    @Column(name = "USER_NAME", length = 25)
    public String getName() {
        return userName;
    }

    private List<Access> accs;

    @OneToMany(mappedBy = "user")
    public List<Access> getAccs(){
        return accs;
    }
    public void setAccs(List<Access> accs) {
        this.accs = accs;
    }
}

@Entity(name = "Application")
@Table(name = "WEB_APP")
public class Application implements java.io.Serializable {
    private Integer appId;
    private String appName;

    @Id
    @Column(name = "APP_ID", nullable = false, length = 22)
    public Integer getAppId() {
        return appId;
    }

    public void setAppId(Integer appId) {
        this.appId = appId;
    }

    @Basic
    @Column(name = "APP_NAME", nullable = false, length = 100)
    public String getAppName() {
        return appName;
    }

    public void setAppName(String appName) {
        this.appName = appName;
    }

}

@Entity(name = "Access")
@Table(name = "APP_ACCESS")
public class Access implements Serializable {

   private User user;
   private AccessPK id;
     
    public Access(){

    }

    public Access(Integer userId, Integer appId){
        this.id = new AccessPK(userId, appId);
    }

   
   @EmbeddedId
   @AttributeOverrides({
         @AttributeOverride(name = "userId", column = @Column(name = "user_id")),
         @AttributeOverride(name = "appId", column = @Column(name="app_id"))
       })
    public AccessPK getId(){
        return this.id;
    }
    public void setId(AccessPK id){
        this.id=id;
    }

    @ManyToOne
    @JoinColumn(name = "user_id", referencedColumnName = "USER_ID")
    public User getUser(){
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }
}

@Embeddable
public class AccessPK implements Serializable {
    @Column(name = "USER_ID")
    private Integer userId;
    @Column(name = "APP_ID")
    private Integer appId;

    public AccessPK() {
    }

    public AccessPK(Integer userId, Integer appId) {
        this.userId = userId;
        this.appId = appId;
    }

    public boolean equals(Object o) {
        if (o instanceof AccessPK) {
            AccessPK that = (AccessPK) o;
            return this.userId.equals(that.userId) &&
                    this.appId.equals(that.appId);
        } else {
            return false;
        }
    }

    public int hashCode() {
        return userId.hashCode() + appId.hashCode();
    }

    public String toString(){
        return "User id: " + this.userId + ", Application id: " + this.appId;
    }
}

When i try execute user.getAccs() i get SQLException ORA-00936: Missing Expression.

logs:
[2007-10-03 18:08:04.525] jdbc/bscs.1.48:prepareStatement(select , c.user_id from APP_USERS o, APP_ACCESS c where (c.user_id = o.USER_ID) and (o.USER_ID = ?),type=1003,concurrency=1007)
[2007-10-03 18:08:04.526] jdbc/bscs.1.48:clearParameters()
[2007-10-03 18:08:04.526] jdbc/bscs.1.48:setInt(1,8595)
[2007-10-03 18:08:04.526] jdbc/bscs.1.48:executeQuery(select , c.user_id from APP_USERS o, APP_ACCESS c where (c.user_id = o.USER_ID) and (o.USER_ID = ?))
[2007-10-03 18:08:04.536] jdbc/bscs.1.48:exn-executeQuery(java.sql.SQLException : ORA-00936: Missing Expression
Additional Information
Attached Files

- Relationships

- Notes
(0002338)
plehov
10-11-07 06:08

entityManager.persist(new Access(1,1)) also generates wrong SQL
for example:

...
 Access ac = new Access();
 ac.setId(new AccessPK(userId, appId));
 em.persist(ac);
...

log:
[2007-10-11 15:52:02.953] begin TransactionXid[01:e47fa697]
[2007-10-11 15:52:02.953] jdbc/bscs.2:start(xid=Xid[01:e47fa697])
[2007-10-11 15:52:19.760] jdbc/bscs.2:isClosed() -> false
[2007-10-11 15:52:19.761] jdbc/bscs.2.24:prepareStatement(select 1 from APP_ACCESS o where ,type=1003,concurrency=1007)
[2007-10-11 15:52:19.858] jdbc/bscs.2.24:executeQuery(select 1 from APP_ACCESS o where )
[2007-10-11 15:52:19.864] jdbc/bscs.2.24:exn-executeQuery(java.sql.SQLException: ORA-00921: unexpected end of SQL command
[2007-10-11 15:52:19.864] )
[2007-10-11 15:52:22.514] rollback Transaction[Xid[01:e47fa697]]
[2007-10-11 15:52:22.514] jdbc/bscs.2:end(xid=Xid[01:e47fa697],fail)
[2007-10-11 15:52:22.515] jdbc/bscs.2:rollback(xid=Xid[01:e47fa697])
[2007-10-11 15:52:22.516] amber detach ua.umc.ejb.user.Access - PK: AccessPK [UserId [null], AppId [null]]
[2007-10-11 15:52:22.517] Unhandled Exception thrown: class com.caucho.ejb.EJBExceptionWrapper
 
(0002460)
ferg
11-07-07 15:18

jpa/0w12, jpa/0w14
 

- Issue History
Date Modified Username Field Change
10-03-07 09:15 westrupp New Issue
10-04-07 08:05 plehov Issue Monitored: plehov
10-11-07 06:08 plehov Note Added: 0002338
11-07-07 15:18 ferg Note Added: 0002460
11-07-07 15:18 ferg Assigned To  => ferg
11-07-07 15:18 ferg Status new => closed
11-07-07 15:18 ferg Resolution open => fixed
11-07-07 15:18 ferg Fixed in Version  => 3.1.4


Mantis 1.0.0rc3[^]
Copyright © 2000 - 2005 Mantis Group
33 total queries executed.
28 unique queries executed.
Powered by Mantis Bugtracker