EJB / EE :: Web Application Entity Manager And PreparedStatement Functionality

Feb 14, 2015

Am trying to develop a web application, and am using the Entity Manager. The web application involves users posting data to the database. How do I incorporate the entity manager together with the prepared Statement functionality to avoid users corrupting the database with SQL tags?

If I have EJB database session beans, when the content of the database changes, does the information on the web page get automatically updated dynamically on the client machine?

View Replies


ADVERTISEMENT

Enterprise JavaBeans :: How To Use Application Managed Entity Manager In EJB

May 9, 2014

I finish reading The EntityManager Interface in JEE tutorial. I know I can use container manager entity manager in EJB, but I want to explore how to use application managed entity manager in EJB.
 
Can I use application managed entity manager in EJB (container management JTA transaction is used)? Where do I should close entity manager if can?
 
The following is an example from JEE tutorial, but didn't find where to calose entity manager. and can I create mutiple EntityManagerFactory objects and Entity Manager objects to use them in a JTA transaction?
 
@PersistenceUnit
EntityManagerFactory emf;
EntityManager em;
@Resource
UserTransaction utx;

[Code] .....

View Replies View Related

Enterprise JavaBeans :: Does Container Managed Entity Manager Is Thread-safe In Stateless Session Bean?

May 8, 2014

I read JEE6 doc and confused with : Does container managed entity manager (injected by PersistenceContext annotation) is thread-safe in stateless session bean in multiple-thread env?
 
See code below, if there are 2 requests to stateless sesion bean in 2 concurrent threads ,  is it using same Entity Manager Instance or not?
 
@Stateless(name = "HRFacade", mappedName = "HR_FACES_EJB_JPA-HRFacade-HRFacade")
public class HRFacadeBean implements HRFacade, HRFacadeLocal {
    @Resource
    SessionContext sessionContext;
   
    @PersistenceContext(unitName = "HRFacade")
    private EntityManager em;
 
[Code] .....

View Replies View Related

Any Limit On How Many Parameters Can Be Passed With PreparedStatement?

Mar 31, 2014

I tried to Google, but was not able to find anything relevant.

I have a sql query where in I am using preparedStatement which goes something like :

select * from test where parameters in ( ?,?,?,?,?,?,?,?,?,?,?,?,?);

Is there a limit on how many "?" characters i.e. parameters can be there in this query?

View Replies View Related

Creating Task Manager Using Java

Dec 5, 2010

I want to create a TASK MANAGER for windows OS using java. Of course i am not expecting any code snippets, that is, what are the classes to be included and moreover HOW to do it.

View Replies View Related

Use GridLayout Manager To Arrange Buttons

Dec 5, 2014

Create a frame with ten buttons, labeled 0 through 9 (Hint: You may create an array of 10 buttons). To exit the program, the user must click on the correct three buttons in order, something like 7-3-5. If the wrong combination is used, a JOptionPane message ““Wrong, try again.” will be displayed. You may use GridLayout Manager to arrange the buttons nicely. My coding :

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Combination extends JFrame
{
private JButton[] numbers= {new JButton("0"),new JButton("1"),
new JButton("2"),new JButton("3"),
new JButton("4"),new JButton("5"),
new JButton("6"),new JButton("7"),
new JButton("8"),new JButton("9")};
 
[code]....

Ok so I don't have any error in this. Only issue I have is my loop goes infinite. I can click on any numbers. I want to limit it for upto three numbers and if they are wrong output as wrong numbers. and If they press right number I want Correct number as output.

View Replies View Related

Swing/AWT/SWT :: How To Drag And Drop Component Within Layout Manager

May 28, 2014

For example, say I have I BoxLayout with a few JButtons in it. How could I make it such that I could drag a JButton such that it could be in front or behind the others?

I've thought about using ComponentMover and just switching to a null layout right before moving it and switch it back right after like bellow, but I'm not sure how to make it keep the change in order.

import java.awt.LayoutManager;
import java.awt.event.MouseEvent;
public class LayoutComponentMover extends ComponentMover
{
private LayoutManager layout;

[code]....

View Replies View Related

Read File From LoginModule Running Under Security Manager

Nov 27, 2013

I have followed the Java tutorial on JAAS Authentication and Authorization. All the sample code in the tutorials works fine also when running under a security manager. Now I am trying to modify the LoginModule class, so that it uses a password file to look up users and passwords, but as soon as I try to run the code under a security manager, I get a Security Exception. I suppose it has something to do with the code havent been granted any access to read the password file? So I tried to add this to the policy file:

grant codebase "file:./sample/module/-" {
permission java.io.FilePermission "sample/module/passwords.txt", "read";
};

It didn't do any difference. why I get this Security Exception?

The only difference from my code to the tutorial code, is that I have added the lines:

Scanner scanner = null;
try {
scanner = new Scanner(new File("src/sample/module/passwords.txt"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}

to the login() method of the SampleLoginModule class...

View Replies View Related

Football Manager - Find Out Optimal First Eleven Amongst 25 Or 30 Players

Nov 26, 2014

I am looking into making a program, that will find out the optimal first eleven (in football or soccer for americans) amongst 25 or 30 players. This is going to apply for a computer game: "Football manager 2015"

I was thinking one class would be the player class that is going to have the variables:

player_number (unique) integer
name string
position (there are eleven positions)
position_rating for each position capable of playing

constructor would be add_player(int number, string name)

and a method would be add_position(position, position_rating)

one player can have more than one positions

another class would be the position

position name (unique) string

that's all I can think of now.

the main class would do a loop

starting with a random or defined position it would do all combinations of every single player into each position.

For example it could start with center forward position. There are 5 available players for that position. Lets say the program picks the first player that is also capable of playing in wide position. If the player is picked for center forward he is not avaialable for wide position.

Then the program would move to the wide position and lets say there are 4 players available. It would pick one.

Once 11 players are selected it would add the 11 ratings.

and start over for a different player in center forward position.

at the end of all loops it would print out the 11 players into their respective positions that got the best score.

View Replies View Related

EJB / EE :: Entity For Multiple PU And Different DB?

Dec 18, 2013

I have a package (JAR_A) for entity and controller definition, for example:

entity: Entity
controller: EntityController

Then I use this jar in other projects/applications that use the entity.

I want to use the same JAR_A with different persistence unit and different database (in particular, mysql and postgresql) but when I define two persistence unit that include the same class, I have an exception.

So, I comment the other PU and compile the project.

there is a smarter way for use same package with different PU ?

View Replies View Related

How To Emulate Functionality In Java

Dec 3, 2014

I'm trying to turn into an android app, but I have limited Java knowledge.It's not a super complex app so I figured I could figure it out on the fly with some tutorials and such. But I need to emulate this curl connection and I'm not sure how in Java.

$url = "http://54.193.106.113/ING004/android1/WebServer/Web/sogame/newControl/nmMail/getMailList?sign=".strtoupper($sign);
$connection = curl_init($url);
curl_setopt($connection, CURLOPT_POSTFIELDS, $finalData);
curl_setopt($connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($connection, CURLOPT_ENCODING, "gzip");

[code]....

View Replies View Related

GUI Mortgage Calculator With No Functionality

Apr 18, 2015

How to make my program look nice. I have to create a mortgage calculator with no functionality, so it basically just has to be a window that looks like this:

Here's my code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MortgageCalculator {
public static void main(String[]args) {
CalcWindow calculator = new CalcWindow();

[Code] .....

Here is the output I am getting:

How do I make my program output look similar to the 1st picture?

View Replies View Related

String Intern Functionality

Nov 11, 2014

I am unable to understand the use of String intern. Why not use Code 1 as given below instead of using intern as in Code 2? Both perform the same functionality.

Code 1:

String s1="Hello";
String s2=s1;

Code 2:

String s1="Hello";
String s2=s1.intern();

View Replies View Related

JSF :: Implement A File Upload Functionality?

Apr 16, 2014

I am trying to implement a file upload functionality. One of the requirement is to display a 'Please Wait!!!' message to the user while the upload is going on. My project currently uses JSF 1.2, Tomahawk, JQuery 1.9, JQuery UI 1.10. I am aware that this can be accomplished using a4j with richfaces, however I am not supposed to add any new library to the existing project. how this can be done?

View Replies View Related

JSP :: How To Add Search Functionality In Registration Form

Mar 17, 2015

I want to add search functionality like for City and State ,country.How Can I Implement it.

I am using Java(JSP,Servlets) as my server side lenguage

I have heared about [URL]...

But what are the other ways to add search functionality like custom searchs and other?

(See Attachment Image, what I want to do)

View Replies View Related

Validate Checkbox Functionality In Java

May 14, 2014

I'm guessing the vehicle checklist is for making your car? So like for the tires there would be 3 options and you check which one you want?

View Replies View Related

EJB / EE :: Relation Between Entity On Server And In Library

Nov 6, 2014

I have the following problem:

I need to make a relation (OneToMany) between a entity on my server and a entity in my library (ManyToOne).

My program consists of 3 main components:

- a client (who uses session beans to query the server)
- a server (which contains entity's)
- a lib which is shared between the client and the server. (which also contains entity's)

Here is the thing I want to do:

Class on my Server:

@Entity
public class ClassOnServer implements Serializable{
@Id
private int uid;
@OneToMany(cascade=ALL, mappedBy="relation")
private Set<ClassOnServer> relation1; //This is no problem, because the server can import the library
}

Class on my Library:

@Entity
public class ClassInLibrary implements Serializable{
@Id
private int uid;
@ManyToOne
private ClassOnServer relation2; //This gives an error because ClassOnServer can not be imported into the library
}

It's not an option to move ClassOnServer to my lib because this would ruin the whole architecture.

View Replies View Related

EJB / EE :: Avoid Persist Entity On Set Methods

Dec 9, 2014

I'm using EclipseLink, WildFly, EJB, postgresSQL and JSF.I'm trying to persist some countries and their localities.So I've:

- Two entities Countries and Localities in which I specify respective columns and relations.
- Abstract Session beans for entity classes: AbstractFacade providing basic crud methods and entity manager.
- Two concrete session bean for entity classes: CountriesFacade and LocalitiesFacade.
- A JSF managed bean named geoJSF.
- A JSF page with a form allowing to insert new country and localities.

In geoJSF I'm injecting via EJB CountriesFacade as property named cf and LocalitiesFacade as property named lf.For the actual inserting country and locality I'm using geoJSF.country and geoJSF.locality. When the form is submitted I'm simply doing:

this.cf.create(this.country);
this.locality.setCountry(this.country); //<- this throw an exception (unique constraint violation) due to the attempt to reinsert this.country
this.lf.create(this.locality);

I disabled all cascade among relations definitions.Based on what I know this.country should appear detached to entity manager so, setting relation the entity manager try to re-persist it.

View Replies View Related

EJB / EE :: Bean Validation Error In JPA When Trying To Persist Entity

Aug 5, 2012

i get this error when trying to Persist a customer Entity in my web application using netbeans with the default glassfish server persistence provider eclipselink(JPA2.0)

error is

SEVERE: javax.validation.ConstraintViolationException: Bean Validation constraint(s) violated while executing Automatic Bean Validation on callback event:'prePersist'. Please refer to embedded ConstraintViolations for details.

the table that i want to write to has the following colums
id ==> primarykey auto increment not null int
name == varchar(45) not null
phone ==> varchar(19)
nationalIdNo ==>varchar(19)
balance ==> bigdecimal(6,2) not null default(0.00)

in my addNewCustomer i only need to set name, phone and nationalIdNo only this is my code

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package session;

import cart.Cart;
import entity.Customer;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

[code].....

why am i getting this error? and how do you do a bean validation?

View Replies View Related

Enterprise JavaBeans :: Accessing Another Bean - No Such Entity

Oct 22, 2008

I am using EJB 2.1 when i am tryinh to access another bean from one bean I am getting :

javax.ejb.ObjectNotFoundException:No such entity the full stack trace is given ...

javax.ejb.ObjectNotFoundException: No such entity!
09:06:05,795 ERROR [STDERR] at org.jboss.ejb.plugins.cmp.jdbc.JDBCFindEntityCommand.execute(JDBCFindEntityCommand.java:46)
09:06:05,795 ERROR [STDERR] at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.findEntity(JDBCStoreManager.java:591)
09:06:05,795 ERROR [STDERR]

[Code] .....

View Replies View Related

JSF :: Inserting Parent And Child Entities Into A Third Entity Using SelectOneMenu?

Oct 31, 2014

The company entity contains companyName, Sector and Segment columns. The mapping is 3 entities (Company, Sector, Segment) where Sector and Segment are used to create a company record. Sector has a OneToMany relationship with Segment and with Company. I put the Sector and Segment values into two select menus as use these to create a Sector and Segment reference for the Company table. I'm getting the following exception:

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row:
a foreign key constraint fails (`testdummy`.`company`, CONSTRAINT `FK_COMPANY_FK_COMPANY_SECTORID` FOREIGN KEY
(`FK_COMPANY_SECTORID`) REFERENCES `sectors` (`SECTORID`))
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)

I'm thinking that the problem is that since the Segment entity is a child of Sector it must be entered through an instance of Sector. Because it's being entered as a separate value I'm getting this error. The problem is Segment is defined as a Set in the Sector entity and I can't figure out how to declare Segment as an instance using its parent entity (Sector).

My code is as follows, starting with the Sector entity:

@Entity
@Table(name = "SECTORSNEW")
public class SectorsNew {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int sectorId;
private String sectorName;
@OneToMany(cascade = CascadeType.PERSIST)

[code]....

View Replies View Related

OO Principles - Reduce Number Of Methods In API Without Losing Any Functionality

Jun 20, 2014

A team of programmers is reviewing a proposed API for a new utility class. After some discussion, they realize that they can reduce the number of methods in the API without losing any functionality. If they implement the new design, which two OO principles will they be promoting?

A. Looser coupling

B. Tighter coupling

C. Lower cohesion

D. Higher cohesion

E. Weaker encapsulation

F. Stronger encapsulation

View Replies View Related

PreparedStatement For MySQL Query - Where Query Seems To Get Cut Off

Mar 21, 2014

I am having a problem with a PreparedStatement for a MySQL query, where the query seems to get cut off. I can't really post a self contained example, because it involves an SQL database.The part of the code with the problem...

Java Code:

public void insertEntry(
Hashtable<String, String> strings,
Hashtable<String, Integer> integers,
Date created, Date paid, boolean enabled)
throws ClassNotFoundException, SQLException {
Class.forName("com.mysql.jdbc.Driver");

[code]....

The output of the whole program, though all it has done so far is create some default values and attempt to insert them with the above code, where the problem occurs.

Debug: SQLpaid = 1990-03-21

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorEx ception: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT enabled=0, username='default_username', created='2000-03-21', paid='1990-' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(DelegatingConstructorAccessorImpl.java:45)

[code]....

View Replies View Related

Passing Values Into Constructors Using Main Or Static Method Functionality

Jan 24, 2014

I just kinda get stuck when it comes to passing values into constructors, using main method or static method functionality. In theory i kind of understand how it work but when i type it, it's totally different! I have to have a junit test too but i guess i could do that in the end.

I have attached the assignment. So, how to proceed with this:
 
public class Flight {
int flight_number, capacity, number_of_seats_left;
String origin, destination;
String departure_time;
double original_price;
 
[Code] ....

View Replies View Related

Mail Reading Functionality Is Not Working Properly Using POP3 Protocol

Mar 17, 2014

My Mail reading functionality is not working properly using POP3 protocol. Actually I can read the mail but the status is not changed as read.

Java Code:

public static void main(String arg[]) throws MessagingException, IOException{
String host = "pop.test.net";
String user = "test@beq.com";
String password = "abc10";
String protocol = "pop3";

[code]....

View Replies View Related

Java EE SDK :: Can Use Filter For Maintaining Session Timeout Related Functionality

Dec 14, 2011

I want to implement session timeout functionality ...so with web.xml file i can specify session timeout ..say 30 min.. Now with filter is it possible for me to redirect the request to login page after session is timeout say after 30 min... What are the other ways...??

Also i want to know whether timeout setting in web.xml will overweight the application server timeout ... I am using struts 1.0 and hibernate...

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved