Help coderanch get a
new server
by contributing to the fundraiser

Simon Joseph Aquilina

Ranch Hand
+ Follow
since Feb 14, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Simon Joseph Aquilina

Hello,

I have the following object definition:



I then have a table PERSON with ID and NAME, and another table PERSON_TO_PERSON with PARENT_ID and CHILD_ID where PARENT_ID and CHILD_ID are FK to PERSON.ID

I have two problems:

My first problem (A) The following will enter two entries in PERSON_TO_PERSON rather then one.



The above will create two entries in PARENT_TO_PARENT with both entries have the same values, i.e.



My second problem (B) is that when I delete Ben, John - even after re-query for the object - still says Ben is his father. After I turn off/on the application John admits he has no father.



I tried to add the @ManyToMany with CascadeType.ALL However this simply deletes both Ben and John from the database.
I know I could also remove Ben from John however what if Ben had many other children? I need to loop through all the children too?
What if I have a requirement to add partners? Would I need to loop through the children and partners, delete Ben from all these, update all these
and than update Ben?

Tim Holloway wrote:If what you are talking about is a homogeneous table with fixed rows and columns, just bind the list of Apples to a JSF datatable tag. When you submit the form containing the datatable, all of its input controls will automatically update the list (Model), providing that all items on the form have valid values.



Do you mean like open faces data table? So if I loop through a List of Apples, and the List has 4 apples. I change the color of the first apple, and add a new apple (therefore I have five apples on screen). When I save (submit), will the List of Apple(s) have five apples and the color field of first apple will be updated. That would be fantastic for me.

Tim Holloway wrote:
If the table is heterogeneous (rows have different sets of columns), there's no simple way to do that, since you'd need to set up a table with dynamically-defined rows. Which isn't too hard to do if you use a control binding, but it does require logic in the backing bean to properly layout the various controls within the display structure. Once that was done and the backing data model properties mapped to their respective controls, once again JSF would automatically transfer data from the model to the view and automatically transfer changes from the view back to the model.



All rows would have the same number of columns in my scenario and all would be required.
10 years ago
JSF
Hello,

My problem is very simple. I have a list of objects in my bean (ex: List<Apple> applies = new ArrayList<Apple>() ).
The object has several fields (ex: supplier, color, width, height, breadth, etc.)
I want to show this list on the front end. However I also want to allow the user to edit the attributes of the apples.

So from the front end I will have like a list of fields where a set of fields is related to a single object in the list.
I would also like to add/delete apples.

What first came to my mind is to map every field in the object Apple to a List. For example if Apple has field suppliers and field color then in the bean I would create two Lists, List<String> supplier, and List<String> color.
From the front end I would display the contents of these Lists rather then the List<Apple> apples.
The name of the field would be the same for each set of attributes.
On save (form submit) the Lists would be re-populated with the field values (changed or not) and then I would be my Apple objects from the bean before saving in database.

However I am not sure if there is something in JSF that can help me achieve this in a simple way, working only with List<Apple> rather than adding additional Lists.

10 years ago
JSF

Chan Ag wrote:Synchronized blocks just create a guarded section. They do not guard the resource. But if you are accessing the resource that you want to protect, outside the guarded section, well it's not protected.



Exactly, that is what I observed after some experiments ...
Using synchronized blocks will not guard the resource, the resource must be developed to guard itself (using synchronized blocks or methods).

Thanks


Hello, I have a quick question on synchronized block. If I have a common object "c" then shouldn't the following code block any access to object "c" until all code in the block is ready?



This seems not to be the case for one of the examples I wrote. Basically I created two objects; JobA and JobB. JobA calls longCount from a synchronized block as above. JobB does not call longCount from a synchronized block. I start JobA and JobB as follows:



The result is as follows:



As one can see, because JobB couldn't care less about what JobA is doing (i.e. - did not use a synchronized block), ultimately it undermines what JobA is doing. If JobB had wrapped its calls to longCount within a synchronized block then first JobA would have finished its count and then JobB would have started.



So my question is the following;

Am I right to assume that synchronized block does not guarantee that the code currently being executed cannot be executed from another thread, while a synchronized method DOES give such guarantee?

What is the use to synchronize on the Common object?

Hello when I try to make use of javax.persistence.TypedQuery I get the error "method createQuery in interface EntityManager cannot be applied to given types". If I make use of javax.persistence.Query I do not get the error (but obviously I have to stay typecasting the result to the wanted object). I did a search on the internet and I found out that this might be a problem with dependencies. I use maven to manage my builds. My original dependencies where as follows:



On the internet I read that TypedQuery where introduced for JPA 2.0 and that I should have used the hibernate stub project for JPA 2.0, i.e.



This did not work either. So I searched for OpenJPA JPA 2.0 library and tried to set this as a dependency, i.e. -



This did not work either! So I was wondering has anyone encountered this problem and actually managed to solve it?
I still get the same error and I cannot understand why!

Note that the error is very strange as it does not fail on the import of javax.persistence.TypedQuery but when I call the createQuery method!



Hello, I have read that unit tests should ideally be independent from one another. However I can think of several scenarios where one unit test cannot be completely independent from another unit test.

For example imagine a simple program that moves a file from Folder A to Folder B.

The first unit test I can think of is to put a file in folder A and check if after a few seconds the file is moved to folder B.
The second unit test is to check the content of the file in folder B and see if this is correct.

However the second test can never be done unless the first test is successful.
What I did in the past is call the first test from the second test

Or maybe JUnit is not the right testing tool for this type of work?

11 years ago

Anayonkar Shivalkar wrote:By default the ResultSet object contains a cursor pointing to beginning and it moves forward only. Also, it can be iterated only once. Thus, to add more functionality (e.g. to move backwards, or to iterate it more than once), 'scrollable' comes into picture.



However the book I am reading seems to be saying that JDBCRowSet will not be scrollable when the ResultSet it wraps is not also scrollable.
Hello,

I am reading Java Tutorials - JDBC. Here I read that JDBC RowSet objects "Add Scrollability and Updatability".
However when I read about JDBCRowSetImp I find the following: "The ResultSet object that is passed to the JDBCRowSetImpl constructor must be scrollable" and "if you have run the method createStatement [yo create a ResultSet] without any arguments (ResultSet.TYPE_SCROLL_SENSITIVE), the ResultSet would not be scrollable and neither would the JDBCRowSet".

So my question is; In what case will a JDBCRowSet Add Scrollability?
Solved ...

Was over complicating things. Here is my working version.

Hello,

I have read about Generics and used them in my code as well. I am now trying to use Wildcards and have a problem. I have the following example.



I solved the first error as follows:



However I cannot understand how to solve the second one. What I want is to be have a list that can contain any Animal (Dogs and Cats).

I must be doing something wrong but I cannot understand what!

Matthew Brown wrote:What you'll find is that although these are both in the source file D.java, the compiled files will be D1.class and D2.class.



You are right, you are right!!! ... I should be ashamed of myself!!
12 years ago
I have created the following example in D.java



I always assumed that to run a java program both class and main method must be public. However eclipse allows me to start either D1 or D2.

What would be the command line argument to start a program from the main method in for example class D1 which is defined in the file D.java?


12 years ago
Hello, I was wondering, is it legal to have an ejb annotated with @LocalBean while having one or more interface of this bean which is annotated with @Local? For example ...

Hello, I am trying to use Maven to generate stubs for an EJB3.1 bean exposed as a Webservice. My example is as follows; I have an EAR with a JAR containing my EJB3.1 bean and a WAR which contains a Servlet that access this bean as a webservice. The bean code is as follows:



From the Servlet I call the webservice as follows:



This works fine. However on some books and the Internet I also found examples using @WebReference to inject an instance in an object of type HelloService as follows.




However I cannot understand how to generate HelloService from HelloBean. From the Internet I found out that JBossWS - JAX-WS Tools wsconsume will generate HelloService.java when given a WSDL file. However I can't seem to make it work when giving it a bean. From my maven project I tried adding the following plugin definition (glassfish project):



However this only generate classes to represent all methods in HelloBean and their return values. In short I still did not manage to generate HelloService from HelloBean so that from my Servlet I can avoid boilerplate code.

Does anyone know how I can generate stubs for an EJB3.1 bean most importantly the xxxService class? Or at least correct me if my reasoning regarding this class is wrong.