public class Main {
public static void main(String[] args) {
Cat cat = new Cat();
cat.setName("Vasyka");
Dog dog = new Dog();
dog.setName("Barbos");
Human human = new Human();
human.setCat(cat);
human.setDog(dog);
System.out.println(human.getDog().voice());
System.out.println(human.getCat().voice());
}
}
interface Animal {
String voice();
}
abstract class Pet implements Animal {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
class Dog extends Pet {
@Override
public String voice() {
return getName() + " says Woof";
}
}
class Cat extends Pet {
@Override
public String voice() {
return getName() + " says Meaw";
}
}
class Human {
private Pet cat;
private Pet dog;
public Pet getCat() {
return cat;
}
public void setCat(Pet cat) {
this.cat = cat;
}
public Pet getDog() {
return dog;
}
public void setDog(Pet dog) {
this.dog = dog;
}
}
public class Main {
public static void main(String[] args) {
try(ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("person.dat", false))) {
Person p = new Person("Sam", 33, 178, true);
Person p2 = new Person("John", 40, 165, false);
oos.writeObject(p);
oos.writeObject(p2);
} catch(Exception ex) {
System.out.println(ex.getMessage());
}
try(ObjectInputStream ois = new ObjectInputStream(new FileInputStream("person.dat"))) {
Person p = (Person) ois.readObject();
System.out.println(p.getName());
System.out.println(p.getAge());
System.out.println(p.getHeight());
System.out.println(p.getMarried());
Person p2 = (Person) ois.readObject();
System.out.println(p2.getName());
System.out.println(p2.getAge());
System.out.println(p2.getHeight());
System.out.println(p2.getMarried());
} catch (Exception e) {
e.fillInStackTrace();
}
}
}
javax.persistence.TransactionRequiredException: No EntityManager with actual transaction available for current thread - cannot reliably process 'remove' call