Solved

<![CDATA in JBuilder enterprise queries

Posted on 2002-07-10
14
217 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
Comment Utility
>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
Comment Utility
I've tried the suggestion by girionis now, but I does not work.

Please help - anyone
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
 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
 

Author Comment

by:steff
Comment Utility
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
Comment Utility
 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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:steff
Comment Utility
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
Comment Utility
>>> 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
Comment Utility
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
Comment Utility
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
Comment Utility
If I can have the points, accept this post as an answer :)
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
>  I tried it 100 times before I gave up.

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

Author Comment

by:steff
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Java 1603 Error 2 42
bunnyEars challenge 6 62
pairs challenge 5 44
Java / Linux and Regular Expressions 11 43
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now