Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

<![CDATA in JBuilder enterprise queries

Posted on 2002-07-10
14
Medium Priority
?
223 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 400 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

721 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