Solved

<![CDATA in JBuilder enterprise queries

Posted on 2002-07-10
14
218 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
 

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

914 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

20 Experts available now in Live!

Get 1:1 Help Now