aspose file tools*
The moose likes JBoss/WildFly and the fly likes JBOSS EntityBean CMP with MySQL Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » JBoss/WildFly
Reply locked New topic
Author

JBOSS EntityBean CMP with MySQL Help

muthulingam Jayakanthan
Ranch Hand

Joined: Feb 27, 2005
Posts: 43
I have setup JBoss-IDE with Eclipse with Jboss. The Jboss Version I use jboss-4.0.2RC1.

1. I have configured MySQL version 5.0.21 to Jboss. and I followed the URL
http://www.cotsec.com/documentation/installation/j2ee_jboss_mysql/index.html#3.%20Add%20the%20Java%20MySQL%20Library
to configure the database with JBoss.


2. I made a small table with MySQL

CREATE TABLE `fortunedb`.`test` (
`id` varchar(10) NOT NULL,
`name` varchar(45) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


3. I made a simple Entity Bean Call Test bean to connect to the test table as follow

ejb-jar.xml::::

<![CDATA[Description for Test]]>
<display-name>Name for Test</display-name>

<ejb-name>Test</ejb-name>

com.account.TestHome
com.account.Test

<ejb-class>com.account.TestCMP</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.String</prim-key-class>
False

<cmp-version>2.x</cmp-version>
<abstract-schema-name>Test</abstract-schema-name>
<cmp-field >
<![CDATA[]]>
<field-name>id</field-name>
</cmp-field>
<cmp-field >
<![CDATA[]]>
<field-name>name</field-name>
</cmp-field>
jboss.xml::::::

<ejb-name>Test</ejb-name>
<jndi-name>ejb/Test</jndi-name>



jbosscmp-jdbc.xml::::


java:/MySqlDS
<datasource-mapping>mySQL</datasource-mapping>


<enterprise-beans>

<ejb-name>Test</ejb-name>
<table-name>test</table-name>

<cmp-field>
<field-name>id</field-name>
<column-name>id</column-name>

</cmp-field>
<cmp-field>
<field-name>name</field-name>
<column-name>name</column-name>
</cmp-field>

</enterprise-beans>


4. I am running a Servlet Client to get the connection

public void init(ServletConfig config) throws ServletException {
try {
Context context = new InitialContext();
Object ref = context.lookup("java:comp/env/ejb/Test");
home = (TestHome) PortableRemoteObject.narrow(ref, TestHome.class);
} catch (Exception e) {
throw new ServletException("Lookup of java:/comp/env/ failed" + e);
}
}

protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException,
IOException {

resp.setContentType("text/html");
PrintWriter out=resp.getWriter();


try {

Test bean = home.findByPrimaryKey("jk");
out.print(bean.getName());
} catch (Exception e) {
out.print(e);
}


5. But when I run this Servlet it gives me the following error

"javax.ejb.FinderException: Find failed: java.sql.SQLException: Syntax error or access violation message from server: "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 'FROM test t0_Test WHERE' at line 1""

Please help me to go further on this. I am totally stuck here and I coukld not realise where I made the mistake.
sam jadhav
Greenhorn

Joined: Jan 12, 2009
Posts: 5
Same problem with me too
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5776
    
    7

Sam, please do not resurrect 3 year old posts, but instead [url=]tell the details[/url] in a new post. For example, do you really have a table called 'fortunedb' located in database 'test'? (That is a horrible table name, by the way, and I would never put anything into the 'test' database.)


JBoss In Action
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JBOSS EntityBean CMP with MySQL Help
 
Similar Threads
CMP beans not entering data in database
won't create tables with jaws.xml
JBOSS EJBQL generate wrong SQL
Entity Bean on JBoss4.0.2
Exception:Attempt to get a lock for a null object ?