Aleksander Zielinski

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

Recent posts by Aleksander Zielinski

You are using container-managed entity manager and container is associating entity manager with the transaction. As for IllegalStateException, you are not allowed to invoke close on container-managed entity manager.
In this case exception will not be thrown. The persist, merge, remove, and refresh methods MUST be invoked within a transaction context when an entity manager with a transaction-scoped persistence context is used. We use application-managed persistence context which by default is EXTENDED, so participating in the active transaction is not needed. However, since entity manager does not participate in transaction and EntityManager.flush method is not invoked 'emp' object state will not be saved to the database.
According to spec:

1). EntityManager.flush method must be called within an active transaction context.
2). It is the responsibility of the application to associate the entity manager with the transaction by calling EntityManager.joinTransaction.

Therefore calling flush, without associating the application-managed entity manger (that was created outside the scope of the active transaction) with the active JTA transaction, results in throwing TransactionRequiredException. According to spec, A and B are wrong.

However, I tried it in Glassfish and it was not required to explicitly call EntityManager.joinTransaction, I was able to sucessfully perform operations from A and B without calling EntityManager.joinTransaction. Glassfish uses Toplink which provides the JPA functionality for the EJB 3.0 Reference Implementation. It is probably another Glassfish's inconsistency with spec.

Originally posted by krishna bulusu:


<pre name="code" class="core">

In the above code, before deleting the employee object, the entity manager make sure that it is synchronize with the database.
Hope this helps.

Merge operation does not synchronize object state with a database, it just makes the instance managed, so it can be used in remove method.
As you quoted, merge operation is performed only to make the instance managed as it was detached. Changes are persisted when a transaction commits, so no changes are written to the database yet. Then refresh is made to update object state with database information.

However the problem lies somewhere else. Merge method returns either a new instance or an existing managed version from the persistence context. Our object is a detached instance therefore we'll get a new object. The new object will be refreshed and since the undoItemChanges method returns reference to our old detached instance we will be working with detached instance with state that has not been refreshed with current database information.

It should look like this:

<pre name="code" class="core">
public Item undoItemChanges(Item item) {
Item refreshedItem = entityManager.merge(item);
return refreshedItem;
[ July 16, 2008: Message edited by: Aleksander Zielinski ]
According to SUN website, there is almost nothing about EJB 2.x on the SCBCD 5 exam, however in MZ notes there are EJB 2.x mentioned sometimes. Wondering if should I pay attention to this...

Would like to ask ranchers who has already taken the exam if there are any questions related in some way or another to the EJB 2.x technology?

Hello Ranchers,

Have a problem with deleting records. When trying to delete inverse side object (Car) and this object's key is used is in join table, it says children were found and operation is not possible. If I set cascade type to REMOVE on "drivers" collection it Car class, it also tries to delete associated Drivers what I don't want.

Is there any way to delete Car and all records in join table that reffers to this Car without deleting Driver?

Will be very grateful for help.

[ August 21, 2007: Message edited by: Aleksander Zielinski ]
[ August 21, 2007: Message edited by: Aleksander Zielinski ]

Thanks guys!

Nicholas, I've got SCWCD, so probably next one will be SCBCD and then SCEA.

Barry, yes I started at the begining of October. To be completely honest it's hard for me to estimate the number of hours. It realy varied on different days, sometimes it was many hours and sometimes I didn't work on the project at all. I can say that my application was almost ready at the begining of December. Then I just had to create help, write choices.txt and documentation for my controller. I uploaded in the middle of January, I did almost nothing during this time, wanted to write my choices.txt, but was just f****ng around I took the essay exam on January 26th and got the result on February 14th. I'm sorry but I can't give you better answer, I wouldn't want to lie about number of hours.

As for GUI guys, I did nothing really fancy. It would be the best to show you how it looks like. Is it ok to show a picture? Are we allowed to paste one here?
17 years ago
Hi everybody,

I have just found out that I have passed the exam. Actually, my result has been available since February 14th, but I have been checking on the wrong website Accidentally I logged on the other one today and there was my result.

This report shows the total number of points awarded for each section. The maximum number of points is 400, to pass you need a score of 320.

Section summary:

I lost points in Server and General Considerations (probably because of the server issues). I guess I unnecessarily wanted to make my server fancy I allowed a user to stop the server without exiting the application and run it on a different port or with a different databse file. However this solution required to unbind and unexport all remote objects so clients that have alreay obtained thier stubs are not able to perform remote calls when server was stopped, but registry was not closed. To do this server had to keep somewhere references to all objects produced by the factory... and so on... and so on... it got a little bit complicated. Everything worked fine and I tried to keep it as simple as possible, but I think the grader considered it as adding unecessary complexity to the application.

I added solution that allowed to lock entire database and lock entire lock manager so the server can be safely stopped. When entire lock manager is locked, clients that are in the middle of the booking can finish their actions to avoid data corruption, but no further locks are granted. When database is locked, operation on the database that has been started can be finished to avoid data corruption, but no further access is granted. Then database can be safely closed.

As for MVC and my GUI, I didn't use Observer-Observale pattern. My Model does not notify the View about changes, Controller is responsible for everything. I even took it to a little extreme, that is all my Controller's methods are private, I was a little bit concerned about this, but I did what I thought was right and justified this solution. I got max points for GUI, so now I know that was a good choice. In short, nobody knows about the Controller. In fact View does not know about Controller and Model, and Model does not know about Controller and View. Controller is the only thing that knows about both about View and Model as it controls everything. There should be some of my posts on this topic if you are interested.

That's what comes to my mind now about my design. If you have any questions feel free to ask, I'll be happy to answer.

Thanks everybody and good luck to those who are going to take the exam!
[ February 25, 2007: Message edited by: Aleksander Zielinski ]
17 years ago
Hi Tom,

Congratulations! Nice Christmas gift!

When did you take essay exam?
Hi Leszek,

What do you mean by saying "is TableModel a GUI class"? Should it reside in GUI code, is that what you are asking about? Well, it all depends on your design. In mine where controller controls everything, controller creates table model every time new data is to be displayed and passes it to the view, so I can say it does not reside anywhere If you use MVC where model notifies view about changes then your table model should reside in the GUI code. Table model is not an application level model, it is the model on Swing level MVC design and its components.

Good luck on the exam, I plan to schedule mine just after New Year. Currently finishing my choices.txt and uploading after Christmas.
Ok, let's no hijack my own thread I'm sending you a PM.

Controller methods issue still actual, eveybody welcome to share their thoughts.
Hi Edisanrdo,

How is it going? I see you are still around

Yes I've been working pretty hard, started at the begining of october and I almost finished. Just have to write the choices.txt, help for the application user and documentation for the controller, that's why I was asking about controller methods to make sure it is ok to make them all private.

Originally posted by Edisandro Bessa:
When you say : model does not know about controller and view, view does not know about controller and model, you are definitely correct !

In most of samples I have ever seen, the View simply is notified by the Model whenever the underlying data changes. It's accomplished by using the Observer Pattern where the View registers itself to the Model and implements a common interface used by the Model to notify its dependents.

Well, using Observer pattern makes the view knows about the model one way or another. It may not hold the reference to the model but it is still coupled with the model through the observer pattern. As you said this is the most common approach, but after reading Mark's posts on MVC I decided to make controller responsible for *everything*, that is: respond to user actions, map them into commands that are sent to the model, then update the view.

I have just read the topic from the second link you provided. Thank you for these. Guys that took part in that topic agree that "regular" MVC supports coupling between the three MVC parts. This is what Ken Blair wrote at the end of its message.

Originally posted by Ken Blair:
As for our current design, we have completely seperated our data from it's presentation as you would in MVC, but it's not using MVC. It's late and I'm not thinking so well, but I believe our design does fit a pattern I just can't remember the name of it, it's similar to MVC.

I'm not sure if this is the same as MVC design that Mark Spritzler was trying to convince people to use, but that is what Mark's design do. Completely separates view and the model, moreover view and model does not know about controller too. They are unaware of the outside world. And that is what supports low coupling. The less you know the better, just do your job and don't care if anyone is interested in it.

In this design any changes are made to controller only. View's purpose is just to look pretty. If I want to use different controller I can do so without touching the view and model code. If I want to change the model, I only have to change the controller, view code stays untouched and the same about model code. If I want to use different view then give it to me, I will just change the controller.

Controller controls everything as the name implies I read Mark posts on this topic and I have to agree that this is the best approach. I'm not sure if this is ok to make all methods private, for me it's not a problem, but don't know about assesor

Thank you for your inputs Edisandro, they are always welcome and highly appreciated. Did you start with your SCJD? If so, I'll be glad to help if I can. I'm getting my B. Sc. this year and planning to write JEE application with JSF and EJB 3.0, want to finish SCJD, so I can start with it. Actually, I could have already finished, but there's always something to improve, so if you didn't start yet, please take my advice and mark your own border - what is enough to do, otherwise you will never end with adding new features

By the way, Mark where are you? Are you still reading this forum?
Hi everybody,

I have a factory that produces remote objects (lets call it RO), I keep a Set of these ROs in the factory so when I stop the server I am able to unexport them all.

RO implements Unreferenced interface so when it crashes or simply exits its unreferenced() method will let know the factory that it can unexport this object and remove it from the Set.

The UnicastRemoteObject.unexportObject method throws NoSuchObjectException, and my question is, is there any possibility (other than the remote object is unreferenced) that object can be removed from table by rmi or any other reason? Object should be unexported when rmi finds out that the remote object is no longer referenced, what about if client would connect and do nothing for 3 days or something? Is this situation possible? Now everything works fine, but I'm not sure how should I handle that exception, because I'm not sure what can cause the object to be removed from the table. I wonder if I should close the server entirely if this happens.

Any comments would be really appreciated.
17 years ago
Hi Cameron,

Thank you for your comment. The thing is that in this design view is not directly calling controller methods. Controller registers itself through "hook" methods.

For example:

MainWindow's listenToBookButton() method adds listener to the button and all the event handling code is in controller. View just stays there and looks pretty. My controller spawns new thread for each action non related to GUI and uses SwingUtilities.invokeLater() to refresh GUI after the thread finishes its task. My controller is about 600 lines of pure of code (without comments and blank lines) and all methods are private. Only constructor is public so the controller can be instantiated. I think that is what the design implies, but would like to hear if someones disagree.