Do you have a sample project that reproduces this? Or at least share the code for the classes. Could be that your B relationship needs to have a @Fetch annotation to be fully hydrated for the load. Update As I presumed, the transitive child is not loaded automatically, so if...

There are two things missing- The type has to be specified on the @RelationshipEntity as well, like this @RelationshipEntity(type = "IsUser") In Organisation.addUser(), add the IsUser to the Person too, something like person.users.add(user);. The entities have to be navigable from both ends. ...

If you want to use your own JDBC code that plays nice with the connections managed by Spring's transaction management you should use DataSourceUtils to obtain the connection -- see http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/jdbc/datasource/DataSourceUtils.html#getConnection-javax.sql.DataSource- In your example, depending on the transaction configuration, the first statement using the JdbcTemplate might not be committed yet,...

You could do something like this: First define PropertySourcesPlaceholderConfigurer bean somewhere in your Spring configuration: @Bean public static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer() { PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer(); ppc.setLocation(new ClassPathResource("application.properties")); return ppc; } This configuration assumes that application.properties file is placed at the root of your classpath. After setting up the property...

Finally, I got an answer from the hibernate team. It seems this is a known issue, and there is only a workaround for it, for now: Add the annotation @Fetch(value = FetchMode.SUBSELECT) to one of the OneToMany collections.

Change your queries to: MATCH (n:Organization) RETURN n You can try: MATCH (n) WHERE {0} IN labels(n) RETURN n but it won't be efficient, why would you want to do that in the first place ? Labels are not allowed as parameters (yet) for query-planner reasons. ...

I'm looking at the unit tests and it looks like you can use the mongo $pull and $push methods using the Update class. https://github.com/spring-projects/spring-data-mongodb/blob/master/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/UpdateTests.java You can see a tutorial here: http://www.dineshonjava.com/2013/01/spring-data-mongodb-update-document.html#.VVexP3UVhBc So you'd be doing something like: Update().pull("arr", 4); Update().push("arr", 5); ...

So after searching for an hour, I have found the solution - i had to look at this post which is not in java but in node.js. Querying a MongoDB based on Mongo ID in a node.js app Thankfully, the language is close to java so I saw that you...

NextShipmentDaoImpl.java looks like this public class NextShipmentDaoImpl implements NextShipmentDao{ private DataSource dataSource; JdbcTemplate jdbcTemplate; public NextShipmentDaoImpl(DataSource dataSource) { this.dataSource = dataSource; } In the above lines of code I had declared JdbcTemplate inside its implementation function itself. Where it is used. And the relevant bean I had declared is: <bean...

Only way I can see is to map an entity to the join table and replace the many-to-many Product<>Category with one-to-many relationships pointing to this new entity from both Product and Category. Such a change would actually be in line with Hibernate best practices: https://docs.jboss.org/hibernate/orm/3.3/reference/en/html/best-practices.html Do not use exotic association...

You want to find all books for a specific author so, given an Author, retrieve all Books whose set of Authors contains the specified Author. The relevant JPQL operator is: http://www.objectdb.com/java/jpa/query/jpql/collection#NOT_MEMBER_OF_ [NOT] MEMBER [OF] The [NOT] MEMBER OF operator checks if a specified element is contained in a specified persistent...

You told hibernate to use myobject_categories as the mapping table. Such a mapping table needs to references: one back to the mapped entity (Employee in this case) and on to the entity that makes up the collection. Probably based on the enum name Hibernate assumed the name category for that...

The default fetch type for @OneToOne is FetchType.EAGER. Therefore, without any hints on how to optimise the query, Hibernate will follow these steps: Select all User's: Hibernate: select user0_.id as id1_1_, user0_.contact_details_id as contact_3_1_, user0_.name as name2_1_ from user user0_ Now eagerly load each User's ContactDetails and UserDetails Hibernate: select...

No, there are no plans. For multiple reasons: ClassTypeInformation is a value object, not an injectable. Instances have to be created on-the-fly very frequently. It simply doesn't make sense to configure an instance of it with Spring, as instances have to be created usually when we encounter a Class of...

1) Is it necessary for me to create an AuditingEntityListener, or should I expect one to be provided from having @EnableJpaAuditing? (it's not clear in the docs about java config) Answer: No you do not need to define AuditingEntityListener bean. Instead you need to specify @EntityListeners(AuditingEntityListener.class) on your domain class....

i tried to put the annotation on the getter and it works. now i can call the @convert to convert enums to strings and visversa when pulling from database. the same problem happened when i added @manytoOne on my class attribute, i got a weired problem, no column was added...

tl;dr The key to that is not so much anything in Spring Data REST - as you can easily get it to work in your scenario - but making sure that your model keeps both ends of the association in sync. The problem The problem you see here arises from...

You should be able to remove the additional dependency as Spring Boot's REST starter already pulls in all dependencies in the correct versions. Spring Boot 1.2.3 refers to the Spring Data train Evans in its second service release. This boils down to Spring Data REST 2.2.2. If you want to...

As per Spring data JPA documentation: Not all Spring Data modules currently support Stream as a return type. Try changing the PagingAndSortingRepository -> JpaRepository and see if it works. Update: I debugged it further and found out that Spring Data JPA 1.8.0 supports Streaming, if you are using some other...

You would define a CustomRepository to handle such scenarios. Consider you have CustomerRepository which extends the default spring data JPA interface JPARepository<Customer,Long> Create a new interface CustomCustomerRepository with a custom method signatures. public interface CustomCustomerRepository { public void customMethod(); } Extend CustomerRepository interface using CustomCustomerRepository public interface CustomerRepository extends JpaRepository<Customer,...

Sorry for the inconvenience, the artifact is currently misplaced in the release repository, though it should be in milestone. We'll move it to milestone asap. Until that happens please add the release repository url 'https://repo.spring.io/release' to your build....

You can change the application properties for the datasource according to the link Gabor Bakos already provided. That depends on the type of the database you want to use. HSQLDB and H2 allow you to specify a file path for the database file, however the database instance itself is...

Not sure how you're actually using MongoRepository, you seem to suggest you're using it directly (it's often a good idea to include your code in the question), but the reference documentation explains the basics of working with this interface (and all repository interfaces in Spring Data, as a matter of...

According to PageRequest implementation: public int getOffset() { return page * size; } so if you set page to 0 the offset value must also be 0 and cannot be larger than total (if total > 0). Check (maybe in debugger) what pageIndex value you pass to spring-data. It may...

So, after sleeping over the problem and looking over the documentation, I did this: @Query("start item=node({self}) match (x:Package) where x.houseAirwayBill= item.houseAirwayBill return count(x)") @JsonIgnore def pieces @JsonProperty("total_pieces") @Transactional Long getPieces(){ return pieces.get("count(x)") as Long } the start item=node({self}) is really important as it binds the self reference to a parameter...

We have a similar use case in our spring-data-examples: @Query("select o from BusinessObject o where o.owner.emailAddress like ?#{hasRole('ROLE_ADMIN') ? '%' : principal.emailAddress}") List<BusinessObject> findBusinessObjectsForCurrentUser(); In your case you could try something like that (in the context of the mentioned spring-data-examples project) The repository method: @Query("select o from BusinessObject o where...

Spring data does provide a level of abstraction to the underlying data store. However, NoSQL stores are a very diverse spectrum, one is a graph database, the other is specialized for storing documents, the third for storing key-value pairs etc. Nonetheless, these are not the differences that you want to...

That piece of code looks like you are "prototyping" something; so it's easier to automatically create a new database (schema, tables, data) on the fly, execute and/or test whatever you want to...and finish the execution. If you want to persist your data and only modify/update it, either use H2 with...

This has been resolved in the latest snapshot release of spring-data, and links are included by default. By updating my POM to include those show below, links appeared on embedded collections <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-rest-webmvc</artifactId> <version>2.4.0.M1</version> </dependency> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-commons</artifactId>...

you need to set lazy to false so it would load all entities(notifications) associated with your entity (user) at load time. this would happen because it fetches data by using a select query to bring the user you requested then getting the notifications associated with it by another query which...

You can do this by using Query Annotation in Spring-data. @Query("select applicant.name from Applicant applicant where applicant.id = :id") Optional<Name> findApplicantNameById(@Param("id") Integer id); ...

Spring allows you to use @Repository, but does not force you to do so. Spring even offers a nice interfacing of JPA that separates the low level concerns (Datasource definition, and transaction management) from the high level ones (DAO, with declarative transactions). There is a chapter in Spring Framework Reference...

This is what I ended up doing. I needed to fetch each attribute at a time (not obvious by tutorials imho) and then at the end in order to return a predicate I have created another specification which I delegate to which has the actual where clause (in this case...

For both of the repositories, you can use the @Query annotation to specify a MongoDB JSON query string that will be used instead of query derived from the method's name (you must know that there's a convention for parsing the repository's method names and for building MongoDB queries). So, by...

You should be able to do this by either: in spring-data 1.5+, overriding the findAll() method in your Interface, adding the @Query annotation and creating a named Query in your Entity class like, for example, below: Entity @Entity @NamedQuery(name = "User.findAll", query="select u from User u order by u.address.town") public...

A query which will get you the result that you need is: SELECT p FROM SemesterEntity s JOIN s.posts p WHERE s.id = :semesterId This query uses the JOIN operator to join the SemesterEntity to the PostEntity across the posts relationship. By joining the two entities together, this query returns...

You should override an equals method in User. From JavaDoc: boolean contains(Object o) Returns true if this list contains the specified element. More formally, returns true if and only if this list contains at least one element e such that (o==null ? e==null : o.equals(e)). With equals you must override...

I see at least one failure related to the generic definition of your classes. The class CatRepositoryImpl extends the classe AnimalRepositoryImpl without any generic Types. (See the following two code snippets of your post) public class CatRepositoryImpl extends AnimalRepositoryImpl implements CatRepositoryCustom { } public class AnimalRepositoryImpl<T extends Animal> { }...

I think you can simply change the query to return boolean as @Query("select count(e)>0 from MyEntity e where ...") PS: If you are checking exists based on Primary key value CrudRepository already have exists(id) method....

You can use the @Query annotation. @Query("SELECT p FROM Person p WHERE p.emailAddress=:emailAddress AND (p.lastName=:lastName OR p.firstName=:firstName)") List<Person> findByEmailAddressAnd(LastnameOrFirstname)(String emailAddress, String lastname, String firstname); ...

The reason all examples are written using Boot is that Boot is indeed the way you should start a new Spring project these days. It free's from a lot of the tedious work of setting up the infrastructure, finding dependencies in the right version etc. To use Spring Data REST...

One way to achieve this is to log the queries on the ES/server-side into the slowlog file. Open your elasticsearch.yml config file and towards the bottom uncomment/edit the two lines below: ... index.search.slowlog.threshold.query.info: 1ms ... index.search.slowlog.threshold.fetch.info: 1ms ... The advantage of this solution is that whatever client technology you're using...

Well, @JohnnyHK's answer is correct, the default _id index in MongoDB is unique, so the problem lies in spring. I've logged this question instead : spring mongorepository is updating or upserting instead of inserting...

From the spring docs Table 2.2 indicates you could use something similar to findByLastnameOrFirstnameOrAge, which would ignore the null values. IF that doesn't get what you want, you'll have to do it with a Specification (see Section 3 of the above document)....

For starter, you're actually working on 2 different EntityManager in your non-working test case: One is the EntityManager autowired into your test by Spring (this one is singleton and should be avoided anyway) and one is the EntityManager created by the EntityManagerFactory configured in your ApplicationConfiguration. At the same time,...

After analyzing the problem and spending some time we realized that the relations should not extend base entity and they need not to be audited the parent entity gives the information required. Its the job of the underneath orm to take care of the the relations.

You have some version mismatches. You are using Spring 4.0, and BeanUtils class in that version has a method findPropertyForMethod which takes one parameter of type java.lang.reflect.Method. Your exception says that another signature of that method is needed (probably by spring-orm-jpa, judging by the logs), one that takes two parameters,...

This is basically invalid usage of the query derivation mechanism. Executing Predicate instances and query methods are a distinct mechanisms that cannot be intermingled. You basically declare a query method that doesn't take any parameters (does not have any criterias) bit then takes a Predicate that Unfortunately the methods declared...

Save by definition is supposed to update an object in the upsert style, update if present and insert if not. Read the save operation documentation on the MongoDb website The insert operation in mongodb has the behavior you expect, but from the MongoRepository documentation it appears that insert is delegated...

You need to use aggregation pipeline here: db.products.aggregate([ {$unwind:"$categories"}, {$match:{"categories.isPrimary":true}}, {$group:{_id:"$_id", numPrimaries:{$sum:1}}}, {$match:{numPrimaries:{$gt:1}}} ]) This will "unwind" the array of categories, keep only the ones that have isPrimary true, "wind" or group them back by original _id summing how many isPrimary values were true and then filter out the documents...

The behaviour that is happening now is as expected as can be seen from the hibernate FAQ.The solution is mentioned in the FAQ here as well If you are looking to do this via JPA refer here. Following is the implementation in Spring data using the following Specification public class...

You need to change the direction of the relationship in your entity Mashape, (entity corresponding to the @StartNode of your @RelationshipEntity TagOnObjectEvaluation). @NodeEntity class Mashape { // ... @RelatedToVia(type = RelTypes.Tag.TAG_ON_OBJECT_EVALUATION, direction = Direction.OUTGOING) private Set<TagOnObjectEvaluation> tagOnObjectEvaluations = new HashSet<TagOnObjectEvaluation>(); } Just point that according to the specifications of @RelatedToVia...

Once you move to Couchbase with a smart client there isn't really much value in moxi; and in fact you'll be introducing an additional network hop (client -> moxi; moxi -> cluster). You can think of the smart clients as conceptually having an embedded moxi - as the smart clients...

That works as designed. An excerpt projection is used whenever an instance of the target type (UserModel in your case) is used within in an _embedded clause. Thus the excerpt is some kind of preview used everywhere the resource itself is not rendered but pointed to. This is usually the...

The jdbcTemplate is going to take care of doing all the sql stuff for you and gets a java.sql.ResultSet back. The ResultSet is the representation of your table data from the query execution. If you were writing plain JDBC code yourself and NOT using Spring, you would have to loop...

The problem is that String username; is annotated with both @Id and @GeneratedValue. @Id means that is should be a primary key, fine it can be a String. But @GeneratedValue means that you want the system to automatically generate a new key when you create a new record. That's easy...

Try using the $regex operator in your query expression: @Query("{'name':{'$regex':?0,$options:'i'}}") public List<DirectoryEntity> findByName(String name); The i option in the regex expression toggles case insensitivity, and allows all letters in the pattern to match upper and lower cases....

i also had this same issue, here was the approach i took. its actually a very small change to the core implementation (which currently only support Query object types), essentially all I did was add another instance of check: if (param instanceof Query) { query = (Query) param; } else...

I was able to get it working with this code: ServerAddress serverAddress = new ServerAddress( environmentHost, Integer.parseInt(environmentPort)); MongoCredential credential = MongoCredential.createCredential( environmentUserName, getDatabaseName(), environmentPassword.toCharArray()); MongoClient client = new MongoClient( serverAddress, Arrays.asList(credential)); This requires the Java MongoDB drivers at at least version 2.13 Here is the section in my pom.xml that...

what causes deserialization problems? I would like to give you bit of background before answering your question, The serialization runtime associates with each serializable class a version number, called a serialVersionUID, which is used during deserialization to verify that the sender and receiver of a serialized object have loaded classes...

If you are using Hibernate with spring-data-jpa you can easily register listeners to achieve application level triggers on inserts and updates. Check this post. I am sure other ORM framework's also provide something similar....

Use a query. Also, note that since the associations are many-to-many, this query might return several actions: select i from Instance i join i.actions action join i.cadSystems cadSystem where action = :action and cadSystem = :cadSystem ...

Eventually I couldn't do it with the MongoRepository. I had to use the MongoOperation / MongoTemplate to do this task. @RequestMapping(value="/XXX", method=RequestMethod.GET) public List getNextPosts(@RequestParam String next) { Query query = new Query(); query.with(new Sort(Sort.Direction.DESC, "_id")); query.limit(5); ObjectId objID = new ObjectId(next); query.addCriteria(Criteria.where("_id").lt(objID)); List<Posts> posts = mongoOperation.find(query, Posts.class); return posts;...

It was the version. It turns out i had an older Spring Data JPA version (1.5.2) and the Top and First keywords where only introduced after Spring Data JPA 1.7.0 . I ended up applying pagination to my queries (usingthe the Pageable method argument)....

You can do this using projections feature of Spring Data REST Here is an explanation https://spring.io/blog/2014/05/21/what-s-new-in-spring-data-dijkstra#user-content-projections-in-spring-data-rest Here is a similar question How to return representations of associations in a Spring Data REST resource? ...

I suggest using a different query - look for date greater than 2015-4-2 00:00:00 and explicitly less than 2015-4-3:00:00:00 Another approach, that I'm less enthusiastic about, would be to to add a field to the document just for the search purpose (e.g. "dateWithoutHour" calculated by java just before saving a...

When using MySQL, it is common for Java developers to use Connector/J as the JDBC driver (since this is the official JDBC driver from MySQL). Developers typically use the com.mysql.jdbc.Driver class as the driver, with a URL such as jdbc:mysql://host[:port]/database. Connector/J offers another driver called the ReplicationDriver that allows an...

You are trying to define ClientServiceImpl as a bean twice, once with @Bean method in config class, and once with @Service annotation in the class itself (the later will be picked up by component scanning triggered by @SpringBootApplication). So either add the @Autowired annotation as suggested by iamiddy to use...

Using AOP would seem to be one approach: an example of using AOP to enrich Spring Data repositories can be found at the below: https://github.com/spring-projects/spring-data-jpa-examples If you can get a reference to the injected EntityManager within the advice then you should be able to get the underlying connection from that...

Definitely you can do that on Abstract classes, and I think it's a good practice in some common cases. Let me give you an example that I'm using in my graph model: @NodeEntity public abstract class BasicNodeEntity implements Serializable { @GraphId private Long nodeId; public Long getNodeId() { return nodeId;...