Results 1 to 6 of 6
  1. #1
    peace76 is offline Member
    Join Date
    Apr 2010
    Posts
    18
    Rep Power
    0

    Default Unknown column 'id' in 'field list'

    Hi. I have a strange problem.

    I get this error ( Unknown column 'id' in 'field list' ). when Im loading an image
    that i uploaded and saved into mysql db as byts[].

    When I google this I found out this can be a bug.

    *entity* // EventPictures
    Java Code:
    @Entity
    @Table(name = "event_pictures")
    @NamedQueries({
        @NamedQuery(name = "EventPictures.customByEvent", query = "SELECT e FROM EventPictures e WHERE e.events = :events")})
    
    public class EventPictures implements Serializable {
        private static final long serialVersionUID = 1L;
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        @Basic(optional = false)
        @Column(name = " id")
        private Integer id;
        .........
        @JoinColumn(name = "events_id", referencedColumnName = "id")
        @ManyToOne(optional = false)
        private Events events;
    
         public EventPictures() {
          }
    
         public Integer getId() {
            return id;
        }
    
        public void setId(Integer id) {
            this.id = id;
        }

    *session* // EventPicturesFacade.java

    Java Code:
    @Stateless
    public class EventPicturesFacade extends AbstractFacade<EventPictures> {
        @PersistenceContext(unitName = "socialeventPU")
        private EntityManager em;
    
        protected EntityManager getEntityManager() {
            return em;
        }
    
        public EventPicturesFacade() {
            super(EventPictures.class);
        }
    
       public List getImage(Events events) {
            Query q = em.createNamedQuery("EventPictures.customByEvent");
            q.setParameter("events", events);
            try {
                return (List) q.getResultList();
            } catch (NoResultException nr) {
                return null;
            }
        }
    
    }

    *servlet* // controller.java

    Java Code:
    else if (!userPath.isEmpty() && userPath.equals("/handlethisevent")) {
    
                String eventId = request.getParameter("eventid");
    
                Events event = eventsFacade.find(Integer.parseInt(eventId));
    
                // get saved posts
                List notes = eventWallFacade.readNotes(event);
    
                // get pictures
                List image = (List) eventPictureFacade.getImage(event); // <--- this failes with the error ( Unknown column 'id' in 'field list' )
    
                request.setAttribute("images", image);
                request.setAttribute("event", event);
                request.setAttribute("notes", notes);
    
                userPath = "/handlethisevent";

    *error* // glassfish serverlog

    Call: SELECT id, description, image, date_uploaded, events_id, users_id FROM event_pictures WHERE ( id = ?)
    bind => [16]
    Error Code: 1054
    Query: ReadObjectQuery(referenceClass=EventPictures sql="SELECT id, description, image, date_uploaded, events_id, users_id FROM event_pictures WHERE ( id = ?)")
    at org.eclipse.persistence.exceptions.DatabaseExcepti on.sqlException(DatabaseException.java:333)
    at org.eclipse.persistence.internal.databaseaccess.Da tabaseAccessor.basicExecuteCall(DatabaseAccessor.j ava:687)
    at org.eclipse.persistence.internal.databaseaccess.Da tabaseAccessor.executeCall(DatabaseAccessor.java:5 30)
    at org.eclipse.persistence.sessions.server.ServerSess ion.executeCall(ServerSession.java:529)
    ..........

    Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorEx ception: Unknown column 'id' in 'field list'
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(DelegatingConstructorAccessorImpl.java:27)

    Can anyone see if I done something wrong. I have 5 more mysql tables that have the same layout as above so it should work.:confused:

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,374
    Blog Entries
    1
    Rep Power
    18

  3. #3
    peace76 is offline Member
    Join Date
    Apr 2010
    Posts
    18
    Rep Power
    0

    Default

    After hours of research and one broken phone and a lot of yelling and banging my head in the wall I found out what error this is.

    It turned out that when creating a column with "blob" attribute. mysql some times dont create all column even if they shows. I had to remove the column id from inside the IDE NetBean and re create it from NetBeans to make it work.

    Before that I tryed to recreate the database from mysql workbench with no success.

    Problem solved.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,374
    Blog Entries
    1
    Rep Power
    18

  5. #5
    peace76 is offline Member
    Join Date
    Apr 2010
    Posts
    18
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Are you creating all columns dynamically?
    No just the column that failed. in this case the "id"

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,374
    Blog Entries
    1
    Rep Power
    18

Similar Threads

  1. insert row and column and delete row and column
    By daredavil82 in forum New To Java
    Replies: 13
    Last Post: 09-22-2011, 06:10 PM
  2. front end display of field description when clicking the field name
    By neils in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 10-29-2010, 11:47 AM
  3. Replies: 1
    Last Post: 07-06-2010, 04:50 PM
  4. Replies: 4
    Last Post: 01-17-2010, 11:13 PM
  5. updating a text field basing on a dropdown list choice
    By amar4java in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 03-13-2009, 10:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •