camelia codarcea

Ranch Hand
+ Follow
since May 08, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by camelia codarcea

Hello ranchers,

I am in a rather big dilemma and I really need your help: in the Hibernate Reference book, there are two examples for named sql-query using join between tables:

1. <sql-query name="personsWith">
<return alias="person" class="eg.Person"/>
<return-join alias="address" property="person.mailingAddress"/>
SELECT person.NAME AS {person.name},
person.AGE AS {person.age},
person.SEX AS {person.sex},
adddress.STREET AS {address.street},
adddress.CITY AS {address.city},
adddress.STATE AS {address.state},
adddress.ZIP AS {address.zip}
FROM PERSON person
JOIN ADDRESS adddress
ON person.ID = address.PERSON_ID AND address.TYPE='MAILING'
WHERE person.NAME LIKE :namePattern
</sql-query>

2. <sql-query name="person">
<return alias="pers" class="Person"/>
<return-join alias="emp" property="pers.employments"/>
SELECT NAME AS {pers.*}, {emp.*}
FROM PERSON pers
LEFT OUTER JOIN EMPLOYMENT emp
ON pers.ID = emp.PERSON_ID
WHERE ID=?
</sql-query>

Now, I have tested these two examples on my own DB: tables Season and Game (also 1:n relation, because in a season there are more games played)

The first example is not working when trying to chose only some columns from the table Game (in the example the table ADDRESS).

<sql-query name="myQuery">
<return alias="season" class="SeasonDAO"/>
<return-join alias="game" property="season.games"/>
SELECT season.IDSEASON AS {season.idSeason},
season.YEARS AS {season.years},
game.RESULT AS {game.result},
game.TEAM1 AS {game.team1},
game.TEAM2 AS {game.team2}
FROM Season season JOIN Game game ON season.IDSEASON = game.IDSEASON
<sql-query>
In this case I get "org.hibernate.QueryException: No column name found for property [result] for alias [game] ".

But the second example is working also for me (displaying all column for the second table) :

<sql-query name="myQuery">
<return alias="season" class="SeasonDAO"/>
<return-join alias="game" property="season.games"/>
SELECT season.IDSEASON AS {season.idSeason},
season.YEARS AS {season.years},
{game.*}
FROM Season season JOIN Game game ON season.IDSEASON = game.IDSEASON
</sql-query>


So, my first question is: why do I have to use the column names with capital letters (IDSEASON, YEARS, etc), even though in the database the column name are not like that (IdSeason, Years, etc)?

Second question is: why it doesn't work for me when I choose what column to take from the Game table ? Am I missing something ?

Thank you
hello,

Thank you for responding. The idea was that for the moment(a prototype) the data we work with is stored in xml files, but later on the data will be stored in database. And I thought that it would be easier just to change the hibernate configuration file to change it form xml files to database mapping. but if I have to write my own Dialect to do that.. then I better quit this idea.
This Driver is called "StelsXML", but as I see, it is not free, you can only get trial version.
Hello,

Do you know if Hibernate can be used with XML files, not with database ? I mean the source is not a SGBD (Mysql, Oracle, DB2, etc), but the data is stored in xml file ?
I have found a JDBC Driver for XML files here: http://www.theserverside.com/news/thread.tss?thread_id=43395, but I cannot see how I can use Hibernate with that.
Do you know anything about this ?

Thank you
Hello,

I'm afraid your code will print neither of the two versions: it will print 012.
In a "for" cycle the increment statement "++i" will have the same result as "i++", because it is evaluated after the instruction in the for are executed:
Hello,

Static variable should be changed inside static syncronised methods in order to be thread-safe.
Two threads that access a static syncronized method, will always block each other, regardless if they are using the same instance or two different instances.
Hello,

I have given the exam last month, in Romania, but I had to call to an authorised Prometric center, and they told me I have to make made an appointment by mail, so I wrote them a mail, giving my full name, my address, my voucher number, and the date and time when I want to give the exam; the next day, they wrote me a confirmation mail, saying that my appointment is made.
If you called to the center and they told you that your voucher was used, then someone made an appointment for that exam based on your voucher number, before you did.
Now, if you received the voucher in a collet, and you trust the person who kept it, I think you should call to Prometric center and tell them that your voucher was used before you received it, and they can track down the date, the place and the name of the person who used it.

Hope it works out for you.
16 years ago
hello,

I'll try to explain to you:
First,a little doze of theory: when you override a method in a subclass, and you create an instance of that subclass, at runtime always the implementation from that subclass will run.
Now, in your example, you have the call() method in Parent class that is overriden in the Child class. That means that when creating Child objects, always call() from Child will run.

Then, theory also sais that the first line in a constructor (even if you don't explicitly write it) , is the call to super() (calls the constructor from the parent class). Ok .. there is an entire set of rules about calling no-args or with-args constructors (cap 2 from K-B book explains in detail ... entire book is excelent).
So, when you write new Child(), the following things will happen:
- the constructor of the Parent class will run.
- there is a call to call() method. but .. as I wrote you before, at runtime, the call() method from Child class will run, not the call() method from Parent class, because you are creating an instance of the Child class. At this stage, the non static attributes from Child class are not yet initialised (b is not 16 yet), but they receive the default value (0 for int)
- now, the constructor from the Parent class is finished running, and you can set the values for the attributes in the Child class, but the "b" variable is already given an explicit value, so at this point b=16
- then another call to call() method is made, and, again, the method from Child class will run
- now, the value of b=16, because you have explicitly set it so.

I hope you understand now.
Hello Ali,

you wrote:
come to think of it: var-agrs won't work either
code:
public static void main(String [] args){
System.out.println("original");
}

public static void main(String... x){
System.out.println("tst");
}


But, actualy, both work, becaue starting with java 1.5, there are accepted the following three signatures for the main method (page 766 K-B book)

static public void main(String[] args)
public static void main(String... x)
static public void main(String bang_a_gong[])

So, the important things are: the method should be static and public, should be called "main". The parameter can be either var-args, or an array of Strings.
Hi,

I never said you should get both "Main Method1" and "Main Method2"!!!
What I said is that the first post is correct, it will compile, but only the first method will be automatically called, because it has the "String[] args" as the list of parameters.

The second method will not be called (it is not explicitly called from the first method), so you cant get also the result "Main Method2".

If you want to get also the "Mai Method2", you should change your code as following:

public static void main(String[] args) {
System.out.println("Main Method1");
main("somethig"); // this calls the overloaded method "main" !!!
}
public static void main(String args){
System.out.println("Main Method2");
}
Hello,

well, you can have two methods "main" with the condition that the list of arguments is different for the two. This is the the principal rule for overloading a method (this is what you are trying to do). This applys not only to "main" method, but to any other method made in Java.
So, the code in your second post will not compile, because the list of parameter is the same (String[] args), but the code in the first post will compile.
At runtime the method "main" with (String[] args) will be automatically called.
yes, I get th error enside Eclipse IDE.

I face searched the net, but I couldnt find any usefull information.
I have the junit-3.8.1.jar, I have put it in the Java Build Path... do I have to make other configurations ?

thank you
hello everybody,

I am currently working on a project with Hibernate and Spring, and I have made some JUnit classes to test the interaction with database.
When I try yo run the test: right click-> run as-> JUnit test, I get the following error:

"The input type of the launch configuration does not exist".

Does anybody know what are the configurations? I haven't done any configurations, I just created a new JUnit class that derives from TestCase

thank you
hello,

I am reading about annotations, and I can't figure out the difference between EJB3 annotations, Hibernate annotations and JDK5 annotations.
All three have the same tags: @Id, @one-to-many etc
Can anyone explain to me, or is there a good tutorial about annotations ?

thank you
hello,

I have found aout that tha first approach is with annotations and the second approach is with XDoclet.
Annotations are more elegant because they checked at compile time.


The second question is still open, the design question.

Thank you