Old dog, new tricks


#1

Hello All,
I’ve been in the industry for many years, however I am totally new to Spring and Couchbase. I think it’s great technology and would like to use the technologies for a project here in CA. I’ve set up the server, populated the buckets, fired up STS and pulled some sample code from github. Does anyone have some simple code that merely retreives a document from the beer-sample bucket using Spring? Most of the examples have been incomplete or I spend hours wrestling with Maven issues :wink:
Thank you so much,


#2

hi @chasisr23
great to hear you are trying out Couchbase and Spring Data :smile:
Unfortunately, using the beer-sample bucket isn’t ideal for trying out Spring Data.

Here’s the thing: Spring Data needs metadata it generates in the content of the documents to correctly deserialize them from JSON. This is typically embodied in the _class JSON attribute. Since beer-sample is a generic-purpose Couchbase sample, this requirement isn’t reflected in the bucket’s contents.

You would probably be better off working from the default bucket and using Spring Data to both save and retrieve your entities.

Perhaps the integration tests would be interesting?
For instance, there’s a Party domain object. You can look at:

  • the associated PartyRepository (its findByAttendeesGreaterThanEqual is simple but interesting enough, for example)
  • the PartyPopulatorListener that generates data (and uses the template’s save method - template is one level of abstraction below repositories -)
  • here is an example of a test that uses the repository

Be sure to also read the documentation :nerd: :book: to familiarize yourself with all these abstractions and how the couchbase spring data implementation covers them.


#3

Thank you for the advice Simon :slight_smile: Yes, this is just the thing I am looking for; I’ll start using the default bucket then and of course read the documentation. I come from a relational database background and I think this stuff is exciting :wink:


#4

Awesome! Don’t hesitate if you need more information or things start to feel too strange :wink: :alien:


#5

Simon,
I have imported the spring-data-couchbase code into STS and I am having an odd problem. When I attempt to build the workspace, I get an error:
internal compiler error: java.lang.NullPointerException at org.eclipse.jdt.internal.compiler.ast.ForeachStatement.resolve(ForeachStatement.java:429) StringN1qlBasedQuery.java /spring-data-couchbase/src/main/java/org/springframework/data/couchbase/repository/query line 0 Java Problem.

It appears the Java Builder in the IDE is having problems digesting StringN1qlBasedQuery.java. The error truly does appear right before the comment section of the class source. Frankly, I’ve not ever seen an error like this. However I am able to build and install without difficulty using Maven. I have tried various JDK compilers without success. I have also tried switching the STS workspace in the event the metadata had been corrupted; no dice. Any ideas? btw: I am using Version: 3.7.3.RELEASE
Build Id: 201602250940
Platform: Eclipse Mars.2 (4.5.2)

Thank you.


#6

Simon,

I checked the log file and the following was of interest:
!ENTRY org.eclipse.jdt.ui 4 2 2016-04-14 22:52:47.976
!MESSAGE Problems occurred when invoking code from plug-in: “org.eclipse.jdt.ui”.
!STACK 1
Java Model Exception: java.lang.NullPointerException


#7

@chasisr23 this appears to be a bug in Eclipse Mars (and it’s even been reported by Oliver Gierke, the Spring Data team lead :smile:).

Looks like it’s been fixed in Eclipse 4.6 Neon, and there are 4.6-based builds of STS available: https://spring.io/tools/sts/all


#8

Great Simon! Thank you, I am downloading the new verison :slight_smile: