Solved

<![CDATA in JBuilder enterprise queries

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

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

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.

Question has a verified solution.

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

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
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…
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.

778 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