top of page

Parenthood Support Group

Public·11 members
Eldar Markov
Eldar Markov

Jpa Error The Entity Has No Primary Key Attribute Defined


You can't. An entity MUST have a unique, immutable ID. It doesn't have to be defined as a primary key in the database, but the field or set of fields must uniquely identify the row, and its value may not change.




jpa error the entity has no primary key attribute defined



Good evening. I'm trying to map a class hierarchy to a single table using JPA/Hibernate and receive an error on my subclass stating "The entity has no primary key attribute defined". The classes are defined as follows:


By default, each entity class maps a database table with the same name in the default schema of your database. You can customize this mapping using the name, schema, and catalog attributes of the @Table annotation.


The name attribute enables you to change the name of the database table which your entity maps. The schema attribute specifies the name of the database schema in which the table is located. And the catalog attribute describes the name of the database catalog that stores the metadata information of the table.


By default, all JPA implementations map each entity attribute to a database column with the same name and a compatible type. The following annotations enable you to perform basic customizations of these mappings. You can, for example, change the name of the column, adapt the type mapping, identify primary key attributes, and generate unique values for them.


You can use the name attribute to specify the name of the database column which the entity attribute map. The attributes updatable and insertable enable you to exclude the attribute from insert or update statements.


If you annotate your primary key attribute with the @GeneratedValue annotation, you can use a database sequence by setting the strategy attribute to GenerationType.SEQUENCE. Or, if you want to use an auto-incremented database column to generate your primary key values, you need to set the strategy to GenerationType.IDENTITY.


You can also map associations between your entities. In the table model, these are modeled as foreign key columns. These associations are mapped as attributes of the type of the associated entity or a Collection of associated entities, in your domain model.


By setting the cascade attribute, you can also tell your persistence provider which entity operations it shall cascade to all associated entities. This can make working with graphs of entities much easier. But you should avoid CascadeType.REMOVE for all many-to-many associations. It removes much more data than you would expect.


If you want to model the association in a bidirectional way, you need to implement a similar mapping on the referenced entity. But this time, you also need to set the mappedBy attribute of the @ManyToMany annotation to the name of the attribute that owns the association. To your persistence provider, this identifies the mapping as a bidirectional one.


Similar to the referencing side of a bidirectional many-to-many association, you can reference the name of the attribute that owns the association in the mappedBy attribute. That tells your persistence provider that this is the referencing side of a bidirectional association, and it reuses the association mapping defined by the owning side.


As you have seen, you only need a relatively small number of annotations to define your domain model. In most cases, you only need to annotate your entity class with @Entity and your primary key attribute with @Id and @GeneratedValue.


When you define an entity object, it must have a primary key or use a RowID attribute (based on the table's ROWID). To do so, you must create a new attribute while you are defining your entity object in the Entity Object Wizard.


Hi Sathees,\\n\\nI am using JPA version 2.0 and Platform EclipseLink 2.4x, and in your blog it is JPA version 2.1 and Platform EclipseLink 2.5x. Does the error come because of this???\\n\\nThanks\\n\\nHimadri\",\"author\":\"username\":\"himadri.chakravorty\",\"displayName\":\"Himadri Chakravorty\",\"groupIcons\":[],\"suspended\":false,\"isCurrentUser\":false,\"parentAuthor\":\"username\":\"satheeskumar.palaniappan\",\"displayName\":\"Sathees Kumar Palaniappan\",\"groupIcons\":[],\"suspended\":false,\"isCurrentUser\":false,\"id\":10813369,\"creationDate\":1396612736000,\"activeRevisionId\":11381604,\"lastActivity\":1396612738000,\"parentId\":10809199,\"originalParentId\":10801267,\"likeCount\":0,\"visibility\":\"full\",\"depth\":0,\"attachments\":[],\"canVoteUpOrCancel\":false,\"relations\":\"canReport\":false,\"visibility\":\"full\",\"canEdit\":false,\"canUseDelete\":false,\"isLiked\":false,\"type\":\"comment\",\"canVoteUpOrCancel\":false,\"canConvertToAnswer\":false,\"canBeModerated\":false,\"canViewRevisions\":false,\"showInReply\":false,\"reported\":false,\"canCancelReport\":false,\"canDelete\":false,\"canVoteDownOrCancel\":false,\"canComment\":false,\"canViewReports\":false,\"isCurrentUserAuthor\":false,\"liked\":false,\"moderatorComment\":false}]},\"10801175\":\"rootParentId\":10801175,\"commentsCount\":3,\"comments\":[\"body\":\"I use "@Id @GeneratedValue long Id;" in my class and the error is removed.\\n\\nThanks\\n\\nHimadri\",\"author\":\"username\":\"himadri.chakravorty\",\"displayName\":\"Himadri Chakravorty\",\"groupIcons\":[],\"suspended\":false,\"isCurrentUser\":false,\"parentAuthor\":\"username\":\"midhun.vp\",\"displayName\":\"Midhun VP\",\"groupIcons\":[\"name\":\"champion\",\"title\":\"This user is an SAP Champion\",\"priority\":14,\"name\":\"mentor-alumni\",\"title\":\"This user is an SAP Mentor Alumnus\",\"priority\":17],\"suspended\":false,\"isCurrentUser\":false,\"id\":10802710,\"creationDate\":1396356111000,\"activeRevisionId\":11372676,\"lastActivity\":1396356114000,\"parentId\":10802620,\"originalParentId\":10801267,\"likeCount\":0,\"visibility\":\"full\",\"depth\":0,\"attachments\":[],\"canVoteUpOrCancel\":false,\"relations\":\"canReport\":false,\"visibility\":\"full\",\"canEdit\":false,\"canUseDelete\":false,\"isLiked\":false,\"type\":\"comment\",\"canVoteUpOrCancel\":false,\"canConvertToAnswer\":false,\"canBeModerated\":false,\"canViewRevisions\":false,\"showInReply\":false,\"reported\":false,\"canCancelReport\":false,\"canDelete\":false,\"canVoteDownOrCancel\":false,\"canComment\":false,\"canViewReports\":false,\"isCurrentUserAuthor\":false,\"liked\":false,\"moderatorComment\":false]}"); const simplifiedQuestionView = JSON.parse("true"); (function() window.pageContext = mergeDeep(pageContext, question: id: 10801267, plug: "fetch-data-from-mysql-database-into-sapui5-applica", votes: 0, questionTitle: "Fetch data from mysql database into SAPUI5 application", isClosed: false, isLocked: false, isRedirected: false, redirectedFromTitle: "", redirectedFromId: "", closedStatusData: JSON.parse(""), userVoted: false, relations: JSON.parse("\"canClose\":false,\"canUnredirect\":false,\"canReport\":false,\"visibility\":\"full\",\"canEdit\":false,\"canUseDelete\":false,\"canReopen\":false,\"type\":\"question\",\"canVoteUpOrCancel\":false,\"canViewRevisions\":true,\"canUnlock\":false,\"reported\":false,\"canVoteDownOrCancel\":false,\"canLock\":false,\"canCancelReport\":false,\"canComment\":true,\"isCurrentUserAuthor\":false,\"canViewReports\":false"), isQuestionAccepted: false , childToViewInfo: id: "" , comments: JSON.parse("\"10804509\":\"rootParentId\":10804509,\"commentsCount\":6,\"comments\":[\"body\":\"Hi Sathees,\\n\\nI am using JPA version 2.0 and Platform EclipseLink 2.4x, and in your blog it is JPA version 2.1 and Platform EclipseLink 2.5x. Does the error come because of this???\\n\\nThanks\\n\\nHimadri\",\"author\":\"username\":\"himadri.chakravorty\",\"displayName\":\"Himadri Chakravorty\",\"groupIcons\":[],\"suspended\":false,\"isCurrentUser\":false,\"parentAuthor\":\"username\":\"satheeskumar.palaniappan\",\"displayName\":\"Sathees Kumar Palaniappan\",\"groupIcons\":[],\"suspended\":false,\"isCurrentUser\":false,\"id\":10813369,\"creationDate\":1396612736000,\"activeRevisionId\":11381604,\"lastActivity\":1396612738000,\"parentId\":10809199,\"originalParentId\":10801267,\"likeCount\":0,\"visibility\":\"full\",\"depth\":0,\"attachments\":[],\"canVoteUpOrCancel\":false,\"relations\":\"canReport\":false,\"visibility\":\"full\",\"canEdit\":false,\"canUseDelete\":false,\"isLiked\":false,\"type\":\"comment\",\"canVoteUpOrCancel\":false,\"canConvertToAnswer\":false,\"canBeModerated\":false,\"canViewRevisions\":false,\"showInReply\":false,\"reported\":false,\"canCancelReport\":false,\"canDelete\":false,\"canVoteDownOrCancel\":false,\"canComment\":false,\"canViewReports\":false,\"isCurrentUserAuthor\":false,\"liked\":false,\"moderatorComment\":false],\"10801175\":\"rootParentId\":10801175,\"commentsCount\":3,\"comments\":[\"body\":\"I use "@Id @GeneratedValue long Id;" in my class and the error is removed.\\n\\nThanks\\n\\nHimadri\",\"author\":\"username\":\"himadri.chakravorty\",\"displayName\":\"Himadri Chakravorty\",\"groupIcons\":[],\"suspended\":false,\"isCurrentUser\":false,\"parentAuthor\":\"username\":\"midhun.vp\",\"displayName\":\"Midhun VP\",\"groupIcons\":[\"name\":\"champion\",\"title\":\"This user is an SAP Champion\",\"priority\":14,\"name\":\"mentor-alumni\",\"title\":\"This user is an SAP Mentor Alumnus\",\"priority\":17],\"suspended\":false,\"isCurrentUser\":false,\"id\":10802710,\"creationDate\":1396356111000,\"activeRevisionId\":11372676,\"lastActivity\":1396356114000,\"parentId\":10802620,\"originalParentId\":10801267,\"likeCount\":0,\"visibility\":\"full\",\"depth\":0,\"attachments\":[],\"canVoteUpOrCancel\":false,\"relations\":\"canReport\":false,\"visibility\":\"full\",\"canEdit\":false,\"canUseDelete\":false,\"isLiked\":false,\"type\":\"comment\",\"canVoteUpOrCancel\":false,\"canConvertToAnswer\":false,\"canBeModerated\":false,\"canViewRevisions\":false,\"showInReply\":false,\"reported\":false,\"canCancelReport\":false,\"canDelete\":false,\"canVoteDownOrCancel\":false,\"canComment\":false,\"canViewReports\":false,\"isCurrentUserAuthor\":false,\"liked\":false,\"moderatorComment\":false]"), answerPager: answersCount: 8, page: 1, pageSize: 10, pageCount: 1, sort: "votes" , answers: JSON.parse("[\"body\":\"It is mandatory that there should be minimum of one entity in Odata defined as primary key. When you are creating a Odata service you can define one primary key to solve this issue.Midhun VP\",\"author\":\"username\":\"midhun.vp\",\"displayName\":\"Midhun VP\",\"groupIcons\":[\"name\":\"champion\",\"title\":\"This user is an SAP Champion\",\"priority\":14,\"name\":\"mentor-alumni\",\"title\":\"This user is an SAP Mentor Alumnus\",\"priority\":17],\"suspended\":false,\"isCurrentUser\":false,\"id\":10801175,\"posted\":1396335561000,\"votes\":0,\"isAccepted\":false,\"isLocked\":false,\"userVoted\":\"\",\"relations\":\"canCancelAccept\":false,\"canUnlock\":false,\"canUseDelete\":false,\"canVoteDownOrCancel\":false,\"canLock\":false,\"canAccept\":false,\"type\":\"answer\",\"canVoteUpOrCancel\":false,\"isCurrentUserAuthor\":false,\"attachments\":[],\"body\":\"Hi Experts,\\n\\nI am getting an error "Servlet ODataServlet is not available". My code is\\n\\npackage model;\\n\\n\\nimport java.io.Serializable;\\nimport javax.persistence.*;\\n\\n\\n\\n\\n/**\\n * The persistent class for the customer_list database table.\\n * \\n */\\n@Entity\\n@Table(name="customer_list")\\npublic class CustomerList implements Serializable \\n @Id @GeneratedValue long Id;\\n private static final long serialVersionUID = 1L;\\n\\n\\n @Column(nullable=false, length=50)\\n private String address;\\n\\n\\n @Column(nullable=false, length=50)\\n private String city;\\n\\n\\n @Column(nullable=false, length=50)\\n private String country;\\n\\n\\n @Column(nullable=false)\\n private int id;\\n\\n\\n @Column(length=91)\\n private String name;\\n\\n\\n @Column(nullable=false, length=6)\\n private String notes;\\n\\n\\n @Column(nullable=false, length=20)\\n private String phone;\\n\\n\\n @Column(nullable=false)\\n private byte sid;\\n\\n\\n @Column(name="`zip code`", length=10)\\n private String zip_code;\\n\\n\\n public CustomerList() \\n \\n\\n\\n public String getAddress() \\n return this.address;\\n \\n\\n\\n public void setAddress(String address) \\n this.address = address;\\n \\n\\n\\n public String getCity() \\n return this.city;\\n \\n\\n\\n public void setCity(String city) \\n this.city = city;\\n \\n\\n\\n public String getCountry() \\n return this.country;\\n \\n\\n\\n public void setCountry(String country) \\n this.country = country;\\n \\n\\n\\n public int getId() \\n return this.id;\\n \\n\\n\\n public void setId(int id) \\n this.id = id;\\n \\n\\n\\n public String getName() \\n return this.name;\\n \\n\\n\\n public void setName(String name) \\n this.name = name;\\n \\n\\n\\n public String getNotes() \\n return this.notes;\\n \\n\\n\\n public void setNotes(String notes) \\n this.notes = notes;\\n \\n\\n\\n public String getPhone() \\n return this.phone;\\n \\n\\n\\n public void setPhone(String phone) \\n this.phone = phone;\\n \\n\\n\\n public byte getSid() \\n return this.sid;\\n \\n\\n\\n public void setSid(byte sid) \\n this.sid = sid;\\n \\n\\n\\n public String getZip_code() \\n return this.zip_code;\\n \\n\\n\\n public void setZip_code(String zip_code) \\n this.zip_code = zip_code;\\n \\n\\n\\n\\n\\n\\npackage main;\\n\\n\\nimport javax.persistence.EntityManagerFactory;\\nimport javax.persistence.Persistence;\\n\\nimport org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext;\\nimport org.apache.olingo.odata2.processor.api.jpa.ODataJPAServiceFactory;\\nimport org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;\\n\\n\\npublic class EmployeeListServiceFactory extends ODataJPAServiceFactory \\n\\n private static final String PERSISTENCE_UNIT_NAME = "try";\\n\\n @Override\\n public ODataJPAContext initializeODataJPAContext()\\n throws ODataJPARuntimeException \\n\\n ODataJPAContext oDatJPAContext = this.getODataJPAContext();\\n try \\n\\n EntityManagerFactory emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);\\noDatJPAContext.setEntityManagerFactory(emf);\\n oDatJPAContext.setPersistenceUnitName(PERSISTENCE_UNIT_NAME);\\n\\n return oDatJPAContext;\\n\\n catch (Exception e) \\n\\n throw new RuntimeException(e);\\n\\n \\n\\n \\n\\n\\n\\n\\n\\nin web.xml\\n\\n\\n\\n try\\n \\n index.html\\n \\n\\n \\n ODataServlet\\n org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet\\n\\n \\n javax.ws.rs.Application\\n org.apache.olingo.odata2.core.rest.app.ODataApplication\\n \\n\\n \\n org.apache.olingo.odata2.service.factory\\n main.EmployeeListServiceFactory\\n \\n\\n 1\\n \\n\\n \\n ODataServlet\\n /emplist.svc/*\\n \\n\\n\\n\\nCan anyone please help me to resolve the error....\\n\\nThanks\\n\\nHimadri\",\"author\":\"username\":\"himadri.chakravorty\",\"displayName\":\"Himadri Chakravorty\",\"groupIcons\":[],\"suspended\":false,\"isCurrentUser\":false,\"id\":10804509,\"posted\":1396419783000,\"votes\":0,\"isAccepted\":false,\"isLocked\":false,\"userVoted\":\"\",\"relations\":\"canCancelAccept\":false,\"canUnlock\":false,\"canUseDelete\":false,\"canVoteDownOrCancel\":false,\"canLock\":false,\"canAccept\":false,\"type\":\"answer\",\"canVoteUpOrCancel\":false,\"isCurrentUserAuthor\":false,\"attachments\":[],\"body\":\"Hi Satheeskumar Palaniappan, \\n \\nI have done all the required things you have mentioned in the blog and I have cross checked with all your comments mentioned above,still I am getting the error as shown below. \\n \\n \\n\",\"author\":\"username\":\"former.member\",\"displayName\":\"Former Member\",\"groupIcons\":[],\"suspended\":true,\"isCurrentUser\":false,\"id\":10956596,\"posted\":1401792291000,\"votes\":0,\"isAccepted\":false,\"isLocked\":false,\"userVoted\":\"\",\"relations\":\"canCancelAccept\":false,\"canUnlock\":false,\"canUseDelete\":false,\"canVoteDownOrCancel\":false,\"canLock\":false,\"canAccept\":false,\"type\":\"answer\",\"canVoteUpOrCancel\":false,\"isCurrentUserAuthor\":false,\"attachments\":[\"id\":1131016,\"fileName\":\"error.PNG\",\"size\":\"21.3 kB\",\"url\":\"/storage/attachments/1131016-error.PNG\",\"isImage\":true],\"body\":\"Hi all, \\n \\ni also done all the settings but till i got the following errors \\n \\njava.lang.SecurityException: class "javax.persistence.PersistenceUtil"'s signer information does not match signer information of other classes in the same package \\n \\njdk1.7.0_60 \\ntomcat 7.0 \\nEclipse Juno Service Release 2 \\nBuild id: 20130225-0426 \\n \\n\",\"author\":\"username\":\"former.member\",\"displayName\":\"Former Member\",\"groupIcons\":[],\"suspended\":true,\"isCurrentUser\":false,\"id\":11298867,\"posted\":1414401722000,\"votes\":0,\"isAccepted\":false,\"isLocked\":false,\"userVoted\":\"\",\"relations\":\"canCancelAccept\":false,\"canUnlock\":false,\"canUseDelete\":false,\"canVoteDownOrCancel\":false,\"canLock\":false,\"canAccept\":false,\"type\":\"answer\",\"canVoteUpOrCancel\":false,\"isCurrentUserAuthor\":false,\"attachments\":[\"id\":1223171,\"fileName\":\"pastedImage_1.png\",\"size\":\"6.5 kB\",\"url\":\"/storage/attachments/1223171-pastedImage_1.png\",\"isImage\":true],\"body\":\"Hi All, \\n \\nI have gone though this blog and its very helpful too. I need more help from you. \\nI am getting the following result but i want output in a structured manner (perfect table) fetching data from MySQL. \\n \\n\",\"author\":\"username\":\"former.member\",\"displayName\":\"Former Member\",\"groupIcons\":[],\"suspended\":true,\"isCurrentUser\":false,\"id\":11299684,\"posted\":1414416387000,\"votes\":0,\"isAccepted\":false,\"isLocked\":false,\"userVoted\":\"\",\"relations\":\"canCancelAccept\":false,\"canUnlock\":false,\"canUseDelete\":false,\"canVoteDownOrCancel\":false,\"canLock\":false,\"canAccept\":false,\"type\":\"answer\",\"canVoteUpOrCancel\":false,\"isCurrentUserAuthor\":false,\"attachments\":[\"id\":1223366,\"fileName\":\"Capture.PNG\",\"size\":\"34.7 kB\",\"url\":\"/storage/attachments/1223366-Capture.PNG\",\"isImage\":true],\"body\":\"Hi All\\n\\nI am trying to fetch the data from MySQL and display it in one of the views in UI5 application project. I was able to display the contents of the table on the browser. For this, I had created a seperate Dynamic web project. I dint make use of oData for fetching the data. Now, I need to bind the servlet to the json model used in one of the views. Can you guys help me in achieving the same ?\\n\\nThanks in advance\",\"author\":\"username\":\"former.member\",\"displayName\":\"Former Member\",\"groupIcons\":[],\"suspended\":true,\"isCurrentUser\":false,\"id\":11464476,\"posted\":1421215799000,\"votes\":0,\"isAccepted\":false,\"isLocked\":false,\"userVoted\":\"\",\"relations\":\"canCancelAccept\":false,\"canUnlock\":false,\"canUseDelete\":false,\"canVoteDownOrCancel\":false,\"canLock\":false,\"canAccept\":false,\"type\":\"answer\",\"canVoteUpOrCancel\":false,\"isCurrentUserAuthor\":false,\"attachments\":[],\"body\":\"Hi, \\n \\nEven I am trying to fetch data from mysql database into my SAPUI5 application. and follow the same blog OData producer using Apache Olingo with MySQL, JPA & Tomcat web server but \\nwhile running the service i am getting screen as shown in below. Can anyone please help me in solving the error.\",\"author\":\"username\":\"former.member\",\"displayName\":\"Former Member\",\"groupIcons\":[],\"suspended\":true,\"isCurrentUser\":false,\"id\":11815630,\"posted\":1435922331000,\"votes\":0,\"isAccepted\":false,\"isLocked\":false,\"userVoted\":\"\",\"relations\":\"canCancelAccept\":false,\"canUnlock\":false,\"canUseDelete\":false,\"canVoteDownOrCancel\":false,\"canLock\":false,\"canAccept\":false,\"type\":\"answer\",\"canVoteUpOrCancel\":false,\"isCurrentUserAuthor\":false,\"attachments\":[\"id\":1369104,\"fileName\":\"error.jpg\",\"size\":\"74.7 kB\",\"url\":\"/storage/attachments/1369104-error.jpg\",\"isImage\":true],\"body\":\"Hey mate,You might be i


About

Welcome to the group! You can connect with other members, ge...

Members

Group Page: Groups_SingleGroup
bottom of page