Question: I have an object hierarchy like this (dismissing all fields like id, setters/getters, etc.):

```
@Entity
class A {
    @OneToOne(cascade=CascadeType.ALL)
    private B b;
}

@Entity
class B {
    @OneToOne(cascade=CascadeType.ALL)
    private A a;

    @OneToOne(cascade=CascadeType.ALL)
    private C c;
}

@Entity
class C {
    private int x;
}

```

All entities have `@Id @GeneratedValue private Long id;`

I use JPA with Hibernate and a MySQL and have a DAO for `A` which does a simple `entityManager.merge(a); entityManager.flush();`

Now, this construct is used in a JSF project, where I create a new `A` with a new `B` but the value for `C` is taken from the database, hence it is an existing entity. This newly filled object is displayed on a page and only saved when I click on a save button, so the creation and the saving are done in two different transactions.

When I try do do a `dao.save(a)`, I get an `org.hibernate.TransientObjectException`, not really surprising since the value for the `c` in class `B` already exists in the database.

The actual question now is: Can I somehow avoid this problem WITHOUT cascading the saving manually? I am talking about dozens of `B`-type classes, each one with dozens of `C`s - this would totally be against my idea of cascading ...

Any ideas appreciated!

Answer: 
I think the problem is in your Complex.cpp. If there are errors compiling the code of the class, the class is unknown and so the identifier Complex, too. 

After a quick view, everthing seem to be correct but your operator functions have some errors:

Incorrect:

```
    //addition
    Complex Complex::operator+(const Complex &number2) const
    {
        return a + number2.a, b + number2.b;
    }

```

Correct:

```
    //addition
    Complex Complex::operator+(const Complex &number2) const
    {          
        return Complex(a + number2.a, b + number2.b);
    }

```

The problems are the return types of your operator methods. They have to be the same as declared. Also you cannot return two variables at the same time. If you want to do so, you have to use [structs](http://www.cplusplus.com/doc/tutorial/structures/) or classes (by calling the constructor of your class Complex with the new values). 

If you want to manipulate the members a and b, you cannot define the methods as "const". If you say a function is const, it means all class members values won't be manipulated by calling this method.
Try making it as simple as possible. Then add parts back until you find your error.

Does this work?

```
#include "complex.h"

int main()
{
    Complex c(3.0, -1.0);

    return 0;
};

```