Mantis Bugtracker
  

Viewing Issue Advanced Details Jump to Notes ] View Simple ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0001050 [Resin] major always 04-12-06 21:01 04-13-06 10:31
Reporter keith View Status public  
Assigned To ferg
Priority normal Resolution fixed Platform
Status closed   OS
Projection none   OS Version
ETA none Fixed in Version 3.0.19 Product Version 3.0.18
  Product Build
Summary 0001050: Bug in generated SQL for @Entity(access=Property) (same as @Entity)
Description I have a simple example that works with field level access, see below

@Entity(access=FIELD)
@Table(name = "rp_property")
public class Property {

    @Id(generate = GeneratorType.AUTO)
    @Column(name = "property_id")
    private int id;

    @Basic
    @Column(name = "title")
    private String title;

    @Basic
    @Column(name = "address")
    private String address;

    
    /**
     * Entities need a zero-arg constructor.
     */
    public PropertyField() {
    }

    /**
     * Constructor for the init servlet.
     */
    public PropertyField(String title, String address) {
        this.title = title;
        this.address = address;
    }

    

    /**
     * Returns the title name.
     */
 
     public String title()
     {
     return title;
     }
    
    /**
     * Returns the address name.
     */
     public String address()
     
     {
     return address;
     }

}

However when I convert it to be property and not field access I get a SQL error due to bad generated SQL, here's the property class

@Entity
@Table(name = "rp_property")
public class Property {
    @Id(generate = GeneratorType.AUTO)
    @Column(name = "property_id")
    private int id;

    @Basic
    @Column(name = "title")
    private String title;

    @Basic
    @Column(name = "address")
    private String address;

    
    /**
     * Entities need a zero-arg constructor.
     */
    public Property() {
    }

    /**
     * Constructor for the init servlet.
     */
    public Property(String title, String address) {
        this.title = title;
        this.address = address;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

        
}


Now when my servlet is modified to list all the properties

Query query = _manager.createQuery("SELECT o FROM Property o");

        
        for (Property property : (List<Property>) query.listResults()) {
            
                        // bean type access
                        out.println("title: " + property.getTitle() + "
");
            out.println("address: " + property.getAddress() + "
");
            
                         // field type access
            //out.println("title: " + property.title() + "
");
            //out.println("address: " + property.address() + "
");
            
        }



I get the following error:

500 Servlet Exception

java.sql.SQLException: You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right syntax
to use near ' o.address, o.title FROM rp_property o' at line 1
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2928)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)
    at com.mysql.jdbc.Connection.execSQL(Connection.java:2994)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:936)
    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1030)
    at com.mysql.jdbc.jdbc2.optional.PreparedStatementWrapper.executeQuery(PreparedStatementWrapper.java:811)
    at com.caucho.sql.UserPreparedStatement.executeQuery(UserPreparedStatement.java:108)
    at com.caucho.amber.query.UserQuery.executeQuery(UserQuery.java:364)
    at com.caucho.amber.query.UserQuery.executeQuery(UserQuery.java:320)
    at com.caucho.amber.ejb3.QueryImpl.executeQuery(QueryImpl.java:137)
    at com.caucho.amber.ejb3.QueryImpl.listResults(QueryImpl.java:85)
    at exampl.PropertyServlet.service(PropertyServlet.java:67)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:92)
    at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:106)
    at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:178)
    at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:229)
    at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:268)
    at com.caucho.server.port.TcpConnection.run(TcpConnection.java:389)
    at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:492)
    at com.caucho.util.ThreadPool.run(ThreadPool.java:425)
    at java.lang.Thread.run(Thread.java:613)

I traced it down to LoadEntityExpr.java

 /**
   * Generates the where expression.
   */
  public void generateSelect(CharBuffer cb)
  {
    cb.append(getEntityType().getId().generateSelect(getTable()));

    EntityType type = getEntityType();
    
    String valueSelect = type.generateLoadSelect(_fromItem.getTable(),
                         _fromItem.getName());

    if (valueSelect != null && ! "".equals(valueSelect)) {
      cb.append(", "); <-- THIS GENERATES AN ERRONEOUS LEADING COMMA
      cb.append(valueSelect);
    }


It may be something else but I've made my class as simple as possible
Steps To Reproduce
Additional Information
Attached Files

- Relationships

- Notes
(0001085)
keith
04-13-06 04:09

UPDATE this is due to misplaced annotation, when I changed the Entity Bean from field to property access I left the annotations with the fields, they should have moved to the getters. Still it is a very misleading and bizarre error.
 
(0001089)
ferg
04-13-06 10:31

The error checking has been improved in 3.0.19. Essentially, this is a validation problem. Amber should have complained that it couldn't find any primary keys at introspection time.

ejb/0u15, ejb/0u16
 

- Issue History
Date Modified Username Field Change
04-12-06 21:01 keith New Issue
04-13-06 04:09 keith Note Added: 0001085
04-13-06 10:31 ferg Note Added: 0001089
04-13-06 10:31 ferg Assigned To  => ferg
04-13-06 10:31 ferg Status new => closed
04-13-06 10:31 ferg Resolution open => fixed
04-13-06 10:31 ferg Fixed in Version  => 3.0.19


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