Posty

Wyświetlam posty z etykietą Coding

Two entities coexisting in one table

Obraz
I have stumbled across small problem. I had an abstract class, which aggregated all mutual properties of an object and two concrete classes. One did not need any additional fields, while the other needed another relation. Idea was to create one table and gather both those concrete objects from it. I have never done it before, so it was interesting thing to discover. I was working on Team abstraction. Team is a collection of heroes. But teams can be lead by someone or self-organized, hence I have three classes, like so: Notes: BaseTeam is an abstract class annotated with @MappedSuperclass . Since it is abstract I cannot instantiate it and with annotation all its properties will be passed to class extending it. Team class is a concrete class extending BaseTeam. It inherits all the properties from its superclass and does not define any new. It is annotated with @Entity and @Table with filled name property.  It is important to fill those properties, so concrete class can re...

Optional finallyLearned()

Optional<Learn> finallyLearned! Yes, this is a post about my long journey with Optionals. Optionals have been around for quite a long time. They came with Java 8, what makes  them almost as long in the industry as... I am, actually, since the first thing I had to do in my first job was learning those strange Stream thingy. Even though so much time passed, I never really saw a purpose for Optionals. That is of course, because I couldn't use them the way intended. At first I wanted to use them exactly like old if-else statements, so: Ugly, isn't it? Considering myself being so edgy, so robust, so futuristic was dimmed by simple thought - why not use basic if-else? What were those silly Optionals thinking? Isn't it reinventing the wheel? Also not being able to chain isPresent() method with orElse() was a total misunderstanding for me. "Of course I would like to cover all possibilities, why can't I with easy syntax?" - I thought. Suddenly, with Java...