Deriving from a class that has Annotation @PostConstruct

After testing this scenario, the @PostConstruct method in the base class WILL automatically be called. The flow goes like this: When the child class is created, you are in the constructor of the child class, you then are forced into the parent class automatically. Once the parent class constructor is done you are sent back … Read more

JAX-RS using exception mappers

Is InvalidDataException getting wrapped in a PersistenceException? Maybe you could do something like the following: @Provider public class PersistenceMapper implements ExceptionMapper<PersistenceException> { @Override public Response toResponse(PersistenceException arg0) { if(arg0.getCause() instanceof InvalidDataException) { return Response.status(Response.Status.BAD_REQUEST).build(); } else { … } } }

What is Weld, JSR-299?

What does Weld do/give you? Weld is the reference implementation of the abstract JSR-299 API, which is better known as CDI, Contexts and Dependency Injection, an API which is provided through javax.enterprise.context and javax.enterprise.inject packages. How does it relate to Java EE 6? JSR-299 is part of Java EE 6 (JSR-316). How would one use … Read more

How to create join table with JPA annotations?

You definitely shouldn’t create User_Group entity as it’s more the underlying database representation than the object oriented one. You can achieve the join table by defining something like: @Entity @Table(name=”USERS”, schema=”ADMIN”) public class User implements Serializable { //… @ManyToOne @JoinTable(name=”USER_GROUP”) Group group; @Entity @Table(name=”GROUPS”, schema=”ADMIN”) public class Group implements Serializable { //… @OneToMany(mappedBy=”group”) Set<User> users; … Read more

java was started but returned exit code = -805306369

Just had this issue, for me it was a corrupted workspace osgi cache. The solution was to run eclipse with the -clean parameter as eclipse.exe -clean After some time, eclipse required to clean up, the workspace selection dialog popped up and I could start eclipse normally again. The -clean parameter is documented in the eclipse … Read more

A clear explanation of system exception vs application exception

An application exception shall be thrown when there is a business-logic error, as opposed to a system error. There is an important difference: application exceptions do not automatically cause a transaction to rollback. The client has an opportunity to recover after an application exception is thrown. Application exceptions are sent to the client without being … Read more

Get the server port number from tomcat without a request

With this: List<String> getEndPoints() throws MalformedObjectNameException, NullPointerException, UnknownHostException, AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); QueryExp subQuery1 = Query.match(Query.attr(“protocol”), Query.value(“HTTP/1.1”)); QueryExp subQuery2 = Query.anySubString(Query.attr(“protocol”), Query.value(“Http11”)); QueryExp query = Query.or(subQuery1, subQuery2); Set<ObjectName> objs = mbs.queryNames(new ObjectName(“*:type=Connector,*”), query); String hostname = InetAddress.getLocalHost().getHostName(); InetAddress[] addresses = InetAddress.getAllByName(hostname); ArrayList<String> endPoints = new ArrayList<String>(); for (Iterator<ObjectName> i = … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)