[jboss-user] [JBoss Seam] - Re: entityManager.persist(Object) not working?

argonist do-not-reply at jboss.com
Wed Apr 4 08:19:31 EDT 2007


I think I have a similar problem like that post. That's why, I join that post.

Suse 10.2 JBOSS 4.0.5.GA EJB 3.0

I tried to get a data from mysql using manager.createQuery(); But entityManager is not working.
 
Bean

  | @Stateless
  | public class ContentBean implements ContentInterface
  | {
  | 	@PersistenceContext(unitName="ponte")
  | 	EntityManager manager; 
  | 	
  | 	public String getContent(long id) {
  | 		Query query = manager.createQuery(
  | 		"select content.content from HTML_CONTENT content where content.id = :id");
  | 		query.setParameter("id", id);
  | 		try{
  | 			String result = (String) query.getSingleResult();
  | 			System.out.println("id = " + id);
  | 			System.out.println("result");
  | 			return result;
  | 		}catch(Exception e){
  | 			System.out.println("Error");
  | 			return "<NULL>";
  | 		}
  | 	}
  | }
  | 

Data


  | @Entity
  | @Table(name="HTML_CONTENT")
  | public class HtmlContent implements Serializable{
  | 	
  | 	private static final long serialVersionUID = 1L;
  | 	
  | 	@Id
  | 	@Column(name="ID")
  | 	private long id;
  | 
  | 	@Column(name="CONTENT")
  | 	private String content;
  | 
  | 	public void setId(long id) {
  | 		this.id = id;
  | 	}
  | 
  | 	public long getId() {
  | 		return id;
  | 	}
  | 
  | 	public void setContent(String content) {
  | 		this.content = content;
  | 	}
  | 
  | 	public String getContent() {
  | 		return content;
  | 	}
  | }
  | 

persistence.xml

  | <?xml version="1.0" encoding="UTF-8"?>
  | 
  | <persistence>
  | 	<persistence-unit name="ponte">
  | 		<jta-data-source>java:/MySqlDS</jta-data-source>
  | 		<properties>
  | 			<property name="hibernate.hbm2ddl.auto" value="none" />
  | 			<property name="hibernate.dialect"
  | 				value="org.hibernate.dialect.MySQLInnoDBDialect" />
  | 		</properties>
  | 	</persistence-unit>
  | </persistence>
  | 

I tried to add @TransactionAttribut annotation, but it is still not working.

Konsole Output after invoking this methode getContent() :
anonymous wrote : 
  | 13:39:47,670 INFO  [STDOUT] [Ljava.lang.StackTraceElement;@503cb2
  | 

Can someone tell me, what is wrong, or? Thanks

regards
Manu

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4034516#4034516

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4034516



More information about the jboss-user mailing list