I'm evaluating Spring Data's support for Couchbase, and have have run across the following issue. Consider the following pseudo-code example where I've two POJO classes, and a repository defined and instantiated for each:
public class Foo
{
@Id
private String _id;
@Version
private Long _rev;
// .. Other data and members.
}
public class Bar
{
@Id
private String _id;
@Version
private Long _rev;
// .. Other data and members.
}
//
// Repositories
//
@Repository
public interface FooRepository extends CrudRepository<Foo, String> {
}
@Repository
public interface BarRepository extends CrudRepository<Bar, String> {
}
Both repositories are utilizing the same Couchbase bucket. Next:
// Create a new Foo object and save it.
Foo f = new Foo( "id_1" );
fooRepository.save( f );
// Now, try fetching a Bar object using the ID of a Foo object (?)
Bar b = barRepository.findOne( "id_1" );
This results in a Bar object being returned, but not properly initialized - no exceptions are raised. The question, is why isn't an error indicated in this scenario? It seems like not much of a stretch to raise an exception when the requested type doesn't match the persisted type. Am I missing something?
FWIW, When I look at the raw documents in Couchbase via the admin console, I observe that each contains a "_class" property with presumably could be used to identify classes used to represent the data, and detect such mis-matches.