Solved

<![CDATA in JBuilder enterprise queries

Posted on 2002-07-10
14
220 Views
Last Modified: 2013-11-24
Using JBulder 6.

There seems to be a problem with writing finder queries using the EJB designer for CMP entity beans.

In ejb-jar.xml, the query should look like this:

<ejb-ql>
 <![CDATA[ SELECT OBJECT(a) FROM UserBean AS a WHERE a.name = ?1 ]]>
</ejb-ql>

When I type "<![CDATA[ SELECT OBJECT(a) FROM UserBean AS a WHERE a.name= ?1 ]]>" in the designer's query field, the corresponding query in ejb-jar.xml looks like the following:
<ejb-ql>
  &lt;![CDATA[ SELECT OBJECT(a) FROM UserBean AS a WHERE a.name = ?1 ]]&gt;
</ejb-ql>

Is there an escape sequence (or character) I should use in the designer's query method to avoid conversion of "<" to "&lt;"?

If I make changes directly to the xml file and then try to build the ejb.jar, my changes are overwritten.

What can I do to solve my problem.

Thanks in advance.
0
Comment
Question by:steff
  • 6
  • 4
  • 4
14 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 7143121
>When I type "<![CDATA[ SELECT OBJECT(a) FROM UserBean AS a WHERE a.name= ?1 ]]>" in the designer's query field, the corresponding
>query in ejb- jar.xml looks like the following:

  Why not do a:

"&lt;![CDATA[ SELECT OBJECT(a) FROM UserBean AS a WHERE a.name= ?1 ]]&gt;"

  in the designer's query field so it will look fine in the ejb-jar.xml (I am not sure if this will work but it is worth trying it).

  Hope it helps.
0
 

Author Comment

by:steff
ID: 7143282
I've tried the suggestion by girionis now, but I does not work.

Please help - anyone
0
 
LVL 35

Expert Comment

by:girionis
ID: 7143708
 Does it matter so much? When the J2EE server is parsing the ejb-jar.xml file it will convert the &gt; and &lt; to the corresponding characters, so at the end of the day I guess it all works properly.

  Does it throw a parsing exception on the ejb-jar.xml file, or are there any errors related to these characters?
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:steff
ID: 7143828
You are wrong.

To a XML parser &lt; means the character <
To a XML parser < means "here something special starts"

So it will not help writing &lt; in ejb-jar.xml, this will mean that I will want

&lt;![CDATA[ SELECT OBJECT(a) FROM UserBean AS a WHERE a.name = ?1 ]]&gt;

as my EQ string

But I want

SELECT OBJECT(a) FROM UserBean AS a WHERE a.name = ?1

as my EQ string

XML parsers does not by default treat spaces as spaces. Therefore I will have to put <![[CDATA[ ... ]]> around my EQ string to tell the XML parser that it should treat spaces as spaces. It is essential that I write <![CDATA[ and NOT &lt;![CDATA[

Anyone knows a solution?

0
 
LVL 35

Expert Comment

by:girionis
ID: 7143894
 Ok I see what you mean. The last thin I can think of is to use the decimal number or the corresponding unicode hex value for them: Instead for < use &#60; (decimal) or \u003C (unicode) and for > use &#62; and \u003E

  I am not sure if this will work as well but you could try it. Otherwise look at JBuilder' settings, you might find something.

  Hope it helps.
0
 

Author Comment

by:steff
ID: 7145454
It will not help.

The hole idea of XML parseres is to interpret these codes as the character they stand for, so that the character itself can be given special meaning. So to an XML parser &lt;, &#60; and \u003C all means the character <, so that < itself can mean "something special".

Anyone?
0
 
LVL 9

Expert Comment

by:doronb
ID: 7154526
Hi,


If I'm not mistaken, the CDATA token is not needed since all the important spaces are the ones INSIDE your SQL statement meaning all the spaces in the String:
"SELECT_OBJECT(a)_FROM_UserBean_AS_a_WHERE_a.name_=_?1"
(which I have converted to and underscore)

An SQL statement does not NEED to have any special format or syntax other than the one set by the SQL rules:
"SELECT [Fields] FROM [Tables] WHERE [Conditions]".

I also think that the 1 appearing at the end of your SQL statement doesn't need to be there.. :)

In the JB6 Wizard, try entering your SQL select statement without the CDATA and see what happens..


Hope this helps,
Doron
0
 

Author Comment

by:steff
ID: 7154738
Hi

I've already tried without the CDATA, that does not work either. When I deploy into JBoss, I get some error regarding den EJB-QL-string. If I insert the CDATA manually it works, so it proves that the CDATA are nessesary - at least if you use JBoss.

Thanx
0
 
LVL 9

Expert Comment

by:doronb
ID: 7154845
>>> When I deploy into JBoss, I get some error regarding den EJB-QL-string

Can you post here the error message?
0
 
LVL 9

Expert Comment

by:doronb
ID: 7154855
From your first post:

>>> Is there an escape sequence (or character) I should use in the designer's query method to avoid conversion of "<" to "&lt;"?

Have you looked in JBuilder's Documentation/Help files?
0
 

Author Comment

by:steff
ID: 7155466
Hi

I wanted to show you the error message, so I tried without the <![CDATA[ and NO ERRORS!!! Strange!

So I guess I works after all. I really dont understand - I tried it 100 times before I gave up.

Thanx
You can have the points if you want
0
 
LVL 9

Accepted Solution

by:
doronb earned 200 total points
ID: 7156451
If I can have the points, accept this post as an answer :)
0
 
LVL 35

Expert Comment

by:girionis
ID: 7156524
>  I tried it 100 times before I gave up.

  It is really weird how computers can work sometimes ]:-)
0
 

Author Comment

by:steff
ID: 7156542
For others with the same problem. Make sure you restart JBoss before you redeploy and x.jar file. JBoss has a tendency to show old errors if x.jar has been deployed before.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
hibernate example for saving data 19 56
JavaFX TableView not displaying correctly 3 59
ejb mdb examples 1 10
passing enum to a method 4 23
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question