Showing posts from 2016

Deleting @ManyToMany parent entity without affecting child on Hibernate

Oh Dear!!

It's a nightmare getting MySQLIntegrityConstraintViolationException when you're designing complex relational database structure for your app. Most of the time hibernate won't complain with your approximation but this won't work when it comes to bidirectional relations.

Let me show an example.

But first consider a scenario that we're making a movie database application. We have two entities and

The use case is,

User can add multiple movies in a list.
And a movie can be added to multiple list.
User can execute CRUD operations on their list. that means user can create, edit and delete his list.
Admin can delete a Movie.

So it's a @ManyToMany relationship right?

Okay lets dig into the example.

Our two entities are:
@Entity(name = "movie")
public class Movie extends BaseEntity {
private String name;
private String type;
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private List<CustomList&g…

EventBus API: Your complete event manager for Android

Did you ever heard about Publish-Subscribe pattern in Software architecture?

Yes. It's a messaging pattern where the senders of the message, called the publishers will never know who are going to receive those messages  and the receivers, also known as the subscribers, won't know who sent those messages as well.

The publishers will just send the message, without knowing who is gonna receive it. They do their work right.

On the other hand, the receivers, I mean the subscribers, will subscribe what kind of message they want to get. Doesn't matter who'll send them. Well, why should they care? They're gonna get what they need, right? :D

Okay, let's change the perspective a little. Think of an event as a message here. Now think about the publish-subscriber pattern. Yes, you got it right!

There will be event publishers instead of message publishers. And the subscribers will receive events instead of messages. So that whenever an event is published (of course by the publis…

How to deploy Spring boot app as .war file

Hello from ToraCode.

If you find your cloud platform doesn't support container service or deploying standalone application you may find it annoying deploying your app in the cloud. But you can still try creating a traditional .war file to deploy into a container like Tomcat 8, Wildfly 10 or other container.

It's very easy to deploy Spring boot app as .war . You have to just follow those few steps.

Extend your application class with SpringBootServletInitializer and override configure() method like this:
public class Application extends SpringBootServletInitializer {

public static void main(String[] args) throws Exception {, args);

protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(Application.class);
Next, update your configuration so that your project can produce .war file rather than .jar file.

If you're using Maven then …

Deploying sample spring boot app using Docker

Hello from ToraCode.

Now that we are set up with Docker virtualisation software. Let's modify our pom.xml a little bit so that we can build our docker image.

We have to add Docker Maven Plugin in our pom.xml file.

Inside our <plugins> </plugins> tag we need to add this plugin.
<plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <configuration> <imageName>toracode/example-app</imageName> <baseImage>java:8</baseImage> <entryPoint>["java", "-jar", "/${}.jar"]</entryPoint> <!-- copy the service's jar file from target into the root directory of the image --> <resources> <resource> <targetPath>/</targetPath> <directory>${}</directory> <in…

How to deploy Spring Boot application using Docker

Welcome to the ToraCode blog. I'm Sayem and I'll discuss how to deploy Spring Boot app on your local machine using docker.

Wait, what is Docker? I didn't know about that!! why didn't you tell us about docker in the first place?

Well, if you don't know about docker yet, it's fine. Let me explain a little bit for you.

Docker is a virtualisation management software for managing containers and images.

Now what is containers and images? okay let me clear some concepts here

A container is a run time environment for images
An image is a software that you run within the containers.
Image is built using layers. Suppose you have an existing image, you added your app and built a new image and other people can build an image on top of your image.

Suppose you've a spring boot app and you built it using Java 8. So your base image is Java 8 and after adding your app you'll create a new image. Just like layers, you see? Java 8 api is base layer, and you added your code/la…