Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within EJB and other Jakarta /Java EE Technologies
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Tim Cooke
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Liutauras Vilda
Sheriffs:
Rob Spoor
Junilu Lacar
paul wheaton
Saloon Keepers:
Stephan van Hulst
Tim Moores
Tim Holloway
Carey Brown
Scott Selikoff
Bartenders:
Piet Souris
Jj Roberts
fred rosenberger
Forum:
EJB and other Jakarta /Java EE Technologies
EJB3.0 example
santhoshkumar samala
Ranch Hand
Posts: 156
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I have created an ejb3.0 entity bean example with @ManytoOne relation. Iam getting a strange error
Caused by: java.sql.BatchUpdateException: Incorrect integer value: '��' for column 'book' at row 1 at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1666) at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1082) at org.jboss.resource.adapter.jdbc.WrappedStatement.executeBatch(WrappedStatement.java:519) at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246) ... 36 more
my example code is as follows:
Book.java
package com.ig.example; import java.util.HashSet; import java.util.Set; import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.OneToOne; import javax.persistence.SequenceGenerator; import javax.persistence.Table; @Entity @Table(name="book") public class Book implements java.io.Serializable{ /** * */ private static final long serialVersionUID = 1L; private Integer id; private String title; private Set<Author> authors = new HashSet<Author>(0); @Id public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}, mappedBy = "book") public Set<Author> getAuthors() { return authors; } public void setAuthors(Set<Author> authors) { this.authors = authors; } public void addAuthor(Author author){ author.setBook(this); this.authors.add(author); } public void removeAuthor(Author author){ authors.remove(author); } public Book() { super(); } @Override public String toString() { return "Book: " + getId() + " Title " + getTitle(); } }
Author.java
package com.ig.example; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; @Entity @Table(name = "author") public class Author implements java.io.Serializable{ /** * */ private static final long serialVersionUID = 1L; @Id private int id; private String name; private Book book; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "book", unique = false, nullable = true, insertable = true, updatable = true) public Book getBook() { return book; } public void setBook(Book book) { this.book = book; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
my stateful session bean has following code :
public void Test() { Book book = new Book(); book.setId(1); book.setTitle("santhosh first example"); Author author1 = new Author(); author1.setId(1); author1.setName("santhosh"); book.addAuthor(author1); em.persist(book); }
Iam using Mysql, can you please tell me what can be the fix for this?
santhosh<br />SCJP,SCWCD
santhoshkumar samala
Ranch Hand
Posts: 156
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I was able to solve the above problem..
I have added
@Id @GeneratedValue
above getId method of each entity.
santhosh<br />SCJP,SCWCD
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Unable to understand exception
Getting Hibernate bidirectional mapping working with annotations
Many to One instead of One to One relationship
org.hibernate.AnnotationException: mappedBy reference an unknown target entity property
EJB 3.0 Entity Bean
More...