Category Archives: English

JUDCon 2013 Brazil

Hello, how are you?

Bellow you will find the material that I used as speaker of the two lectures in JUDCon 2013.

JSF and EJB +JPA.

lectures

I hope you like it. [=

PS.: Portuguese Only

uaiHebert at JUDCon Brazil 2013

Hello, How are you?

Passing by to say that I will be present at JUDCon 2013 as a speaker.

capa

http://www.jboss.org/en/events/JUDCon/2013/brazil

See you there! \o_

EasyCriteria on Maven

Hello, how are you?

We are happy to announce that EasyCriteria is now on Maven Repository.

To use it just add the line below in the pom.xml:

<dependency>
	<groupId>uaihebert.com</groupId>
	<artifactId>EasyCriteria</artifactId>
	<version>2.1.0</version>
</dependency>

Simple and easy. The version 2.1.0 was released to adapt the pom.xml to the Maven requirements.

I hope you like this news! =D

http://easycriteria.uaihebert.com

Released my First book: Effective JSF

Hello, how are you?

My first book were released today! Unfortunately is in portuguese only.

capa

It talks about best practices with JSF and has 200 pages.

If you have interest in it: http://www.casadocodigo.com.br/products/livro-jsf-eficaz

See you soon. \o_

Thank you DZone

The DZone guys sent me this cool gift!

This gift were sent to the bloggers that most helped the DZone, and I was one of them! =D

DZone gif

EasyCriteria 2.0 – JPA Criteria should be easy

Hello, how are you?

It has been a long time since my last post, but I was not doing nothing during this time.

In the post today we will see about the new version of the framework named EasyCriteria. At the end of this post we will see what is to come here in the blog.

Unfortunately the JPA criteria has a huge problem that is its verbosity. Why not make easier? Thinking like this that EasyCriteria framework were born and now it is on version 2.0.

To do a simple JPQL with the JPA Criteria the following code would be needed:

CriteriaQuery<Person> criteriaQuery = criteriaBuilder.createQuery(Person.class);
Root<Person> root = criteriaQuery.from(Person.class);
criteriaQuery.select(root);
TypedQuery<Person> query = entityManager.createQuery(criteriaQuery);
query.getResultList();

Notice all the code needed to do the query: select p from Person p.

Check below how easy it is to do the same Criteria with EasyCriteria:

EasyCriteria<Person> easyCriteria = EasyCriteriaFactory.createQuery(entityManager, Person.class);
easyCriteria.getResultList();

The difference between version 1.0 and the 2.0 version is in the reduction of methods into generic methods. To compare methods with =, >=, <, <=, and other methods just use the API like below:

easyCriteria.andGreaterThan("hairSize", 10.4f); // >

easyCriteria.andGreaterOrEqualTo("height", 11.00d); // >=

easyCriteria.andLessThan("totalBooksOwned", 30L); // <

easyCriteria.andLessOrEqualTo("firstJobDate", firstJobDate); // <=

easyCriteria.andJoinEquals("dogs", "age", 15); // =

easyCriteria.andJoinStringIn("dogs", "name", names); // value in (x, i, z, ...)

easyCriteria.andJoinStringLike("dogs", "name", "%y");

One of the ideals of the EasyCriteria framework is to expose the lower number possible of API to the user. Thinking like this, EasyCriteria added the “OR” condition to its API without new classes.

Take a look below to see how to do queries with OR:

select s from Song s where s.id = 1 or s.length = 40 or s.artist = 'Group 1 Crew'
easyCriteria.orEquals("id", 1).orEquals("length", 40).orEquals("artist", "Group 1 Crew");

Another type of OR could be done:

select s from Song s where (s.id = 1) or (s.id = 2) or (s.length = 40) or (s.artist = 'Group 1 Crew')
easyCriteria.orEquals("id", 1, 2).orEquals("length", 40).orEquals("artist", "Group 1 Crew");

And it is possible to do complexes queries cases like:

select s from Song s where (s.totalDownloads = 20 or s.weight = 10.00) and (s.price = 20.00 or s.type = :type)
easyCriteria.orEquals(1, "totalDownloads", 20L).orEquals(1, "weight", 10.00f).orEquals(2, "price", 20.00d).orEquals(2, "type", SongType.PRAISE);

The idea of index were added to the API to be used with a group of OR. The first OR group is composed of “totalDownloads” and “weight”, the second group has “price” and “type” as elements.

As default index the value 1 is always used. The criteria above could be written as:

easyCriteria.orEquals("totalDownloads", 20L).orEquals("weight", 10.00f).orEquals(2, "price", 20.00d).orEquals(2, "type", SongType.PRAISE);

It is possible create a query to do the inverse of the query above, AND separated by OR:

select s from Song s where (s.id = 1 and s.name = 'Sing Out') or (s.id = 2 and s.name = 'Alive')
easyCriteria.addAndSeparatedByOr(1, "id", 1).addAndSeparatedByOr(1, "name", "Sing Out").addAndSeparatedByOr(2, "id", 2).addAndSeparatedByOr(2, "name", "Alive");

That is all for today, I hope you like the new version. It will take a long time to consider this framework complete. Helping with the OR functionality I could count with João Neves (http://about.me/joaonevesfilho) and Sasaki (http://curriculum.rodrigosasaki.com/).

Here it is possible to see the framework official page: http://easycriteria.uaihebert.com/. And the best, it is open source (http://code.google.com/p/easy-criteria/).

Other fact about the framework is that it is 100% covered with tests using Cobertura. EasyCriteria was tested with OpenJPA, EclipseLink and Hibernate. Now it is time to ask for your help. It was found bugs in the tested implementations; it would be wonderful if you spare 5 minutes of your time voting in the bugs. With your vote the bug could be corrected faster.

EclipseLink: https://bugs.eclipse.org/bugs/show_bug.cgi?id=386354
OpenJPA: https://issues.apache.org/jira/browse/OPENJPA-2333
Hibernate: https://hibernate.onjira.com/browse/HHH-7985

What is to come in the blog? It took so much time for me to write this post because I am finishing my first book. If God’s will, the book will be released in March.

In this pause of new posts here, I have studied a lot of Maven and I want my next post to be about a mini book about a basic Maven and full web applications. Yes, I said “applications” in plural. [=

See you soon. \o_

JPA Mini Book – First Steps and detailed concepts

Hello, how are you?

Today we will see about JPA: what is the persistence.xml file used for, how to create an entity, mapping easy and complex ids, creating relationships between the entities, automatically entity persistence and more.

Today we will see:

  • Page 02: Reasons that led to the creation of JPA
  • Page 03: What is JPA? What is a JPA Implementation?
  • Page 04: What is the persistence.xml file used for? And its configurations?
  • Page 05: Entity definitions. What are the Logic and Physical annotations?
  • Page 06: Id Generation: Definition, using Identity or Sequence
  • Page 07: Id Generation: TableGenerator and Auto
  • Page 08: Simple Composite Key
  • Page 09: Complex Composite Key
  • Page 10: How to get an EntityManager
  • Page 11: Mapping two or more tables in one entity
  • Page 12: Mapping Hierarchy: MappedSuperclass
  • Page 13: Mapping Hierarchy: Single Table
  • Page 14: Mapping Hierarchy: Joined
  • Page 15: Mapping Hierarchy: Table per Concrete Class
  • Page 16: Pros/Cons of each hierarchy mapping approach
  • Page 17: Embedded Objects
  • Page 18: ElementCollection – how to map a list of values into a class
  • Page 19: OneToOne unidirectional and bidirectional
  • Page 20: OneToMany/ManyToOne unidirectional and bidirectional
  • Page 21: ManyToMany unidirectional and bidirectional
  • Page 22: ManyToMany with extra fields
  • Page 23: How the Cascade functionality works? How should a developer use the OrphanRemoval? Handling the org.hibernate.TransientObjectException
  • Page 24: How to delete an entity with relationships. How to know which relationships are raising the exception
  • Page 25: Creating one EntityManagerFactory by application
  • Page 26: Understanding how the Lazy/Eager option works
  • Page 27: Handling the “cannot simultaneously fetch multiple bags” error

Just one more observation: I will not create a PDF file of this post. Just to create this material I already take several hours of code formatting, images production, translate all text to the English language and texts adjusts in this blog page. I am sorry, but there is no way to create a PDF file, maybe sometime later but I will not promise.

JSF Mini Book – Tips, concepts and good practices

Hello, how are you?

This post was written as an article to a Brazilian Java magazine. Unfortunately it was not published =(. I decided to post it here! =D

This post will display tips, concepts and solutions to developers that works with JSF 2.0 every day. We will see the concepts and the right way of using the JSF to help those who works with this technology or has interest in learning it – students or developers that works with others frameworks. Using this tool without knowledge of it will give more problems to your software instead solutions. It is really needed to understand how the JSF works, how it handles each user action request and how it is possible to build a software code that will optimize the JSF usage.

We will see some technical questions like: importing images/javascript into the pages, how to upgrade a JSF 1.2 app to a JSF 2.0, using Ajax that is a technology of asynchronously requests, and more; we will see some needed theory that is usually set aside.

With JSF we will be able to face one of the major problems of the web technology, code reuse. The JSF allow us to reuse the code of pages, javascript and validations in Java code that are used in the pages. When we reuse the code we will reduce the maintenance time expend, the change impacts will reduce also and others.

Today we will see:

  • Page 02: Creating a JSF project
  • Page 03: How to import CSS/Images/JavaScript as Library
  • Page 04: XHTML page reuse with Facelets
  • Page 05: JSP x Facelets
  • Page 06: Hiding the comments of the xhtml page
  • Page 07: Avoiding @SessionScoped type. Check all Scope Types
  • Page 08: Avoiding the use of logic in the xhtml page
  • Page 09: Use the h:outputLink to navigate
  • Page 10: Ajax with JSF 2.0
  • Page 11: Smoothing the JSF development
  • Page 12: Upgrading from JSF 1.2 to 2.0
  • Page 13: How to receive null value from the view
  • Page 14: Choosing between action and actionListener
  • Page 15: Flash Scope
  • Page 16: Dot no mix JSF Implementations
  • Page 17: Internationalization as good practice
  • Page 18: JSF 2.2 new features

This post is a celebration for the mark of 200k of viewers that we received in the two years of existence of this blog.

“The Father of Java” uses Jelastic

Hello, how are you?

Today we will have an unusual post, it is more like a good news about this framework that is getting its space in the development world. Jelastic has as characteristic to work as a container of containers.

This news were sent to me by Judah Johns from Jelastic.

As far as we can tell, this is the first PaaS that Dr. Gosling has given his endorsement. We reached out to him to confirm it, and sure enough, it turns out that he is a very happy Jelastic user and is very excited about what he can do with it and what he will be doing with it in the near future.

Though I know that in our community, most everyone knows who James Gosling is, there a lot of younger guys learning Java that have never heard of him, like my 13 year-old brother, Daniel, who is quite an avid Java coder. So, who is James Gosling?

The Dr. James Gosling Bio

This bio comes from Gosling’s own blog: James Gosling received a BSc in Computer Science from the University of Calgary, Canada in 1977. He received a PhD in Computer Science from Carnegie-Mellon University in 1983. The title of his thesis was “The Algebraic Manipulation of Constraints”. He spent many years as a VP & Fellow at Sun Microsystems. He has built satellite data acquisition systems, a multiprocessor version of Unix, several compilers, mail systems and window managers. He has also built a WYSIWYG text editor, a constraint based drawing editor and a text editor called `Emacs’ for Unix systems.

At Sun his early activity was as lead engineer of the NeWS window system. He did the original design of the Java programming language and implemented its original compiler and virtual machine. He has been a contributor to the Real-Time Specification for Java, and a researcher at Sun labs where his primary interest was software development tools. He then was the Chief Technology Officer of Sun’s Developer Products Group and the CTO of Sun’s Client Software Group. He briefly worked for Oracle after the acquisition of Sun. After a year off, he spent some time at Google and is now the chief software architect at Liquid Robotics where he spends his time writing software for the Wave Glider, an autonomous ocean-going robot.

EasyCriteria 1.0 released

Hello, how are you?

This post will talk about the new functionalities of EasyCriteria.

EasyCriteria is a tool (Open Source) to make easier the JPA Criteria code for any kind of JPA implementation. EasyCriteria has 100% of coverage on its tests with JUnit and it is tested with: Hibernate, OpenJPA and EclipseLink.

If you want to understand the Criteria ideal and how to apply it to your code check this post: EasyCriteria – An easy way to use the JPA Criteria

The new EasyCriteria functionalities are:

  • Join with conditions
  • Query Pagination

Now it is possible to do a Join and add parameters to it:

EntityManager em = emf.createEntityManager();
EasyCriteria<Person> easyCriteria = EasyCriteriaFactory.createQueryCriteria(em, Person.class);

easyCriteria.innerJoin("dogs", Dog.class);
easyCriteria.whereJoinEquals("dogs", "name", "Dark");
easyCriteria.whereJoinStringNotIn("dogs", "name", names); // names is a List<String>
easyCriteria.whereJoinStringLike("dogs", "name", "M%");
easyCriteria.whereJoinListIsEmpty("dogs", "cars");
easyCriteria.whereJoinAttributeIsNull("dogs", "nickName");
easyCriteria.whereJoinStringBetween("dogs", "name", "A", "L");

The query can be paginated:

EasyCriteria<Dog> easyCriteria = EasyCriteriaFactory.createQueryCriteria(getEntityManager(), Dog.class);
easyCriteria.setFirstResult(0);
easyCriteria.setMaxResults(5);

This new version also has 100% of code coverage.

Click here to download the code of this post with EasyCriteria. With this code you can test EasyCriteria as you like.

In the project page (http://easycriteria.uaihebert.com/) you will find all documentation.

If you have any doubt, just post it.

See you soon! \o_