-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DATAJPA-50 - Introduced support for usage of @IdClass.
Introduced to support @IdClass to define entity ids. The JpeMetamodelEntityInformation builds instances of the annotated @IdClass in case any of the attributes of the entity declared in the @IdClass has a non-null value.
- Loading branch information
Showing
8 changed files
with
457 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
src/test/java/org/springframework/data/jpa/domain/sample/SampleWithIdClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright 2012 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.data.jpa.domain.sample; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.Id; | ||
import javax.persistence.IdClass; | ||
|
||
import org.springframework.data.domain.Persistable; | ||
|
||
/** | ||
* Sample entity using {@link IdClass} annotation to demarcate ids. | ||
* | ||
* @author Oliver Gierke | ||
*/ | ||
@Entity | ||
@IdClass(SampleWithIdClassPK.class) | ||
public class SampleWithIdClass implements Persistable<SampleWithIdClassPK> { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
@Id | ||
Long first; | ||
|
||
@Id | ||
Long second; | ||
|
||
private boolean isNew; | ||
|
||
protected SampleWithIdClass() { | ||
this.isNew = true; | ||
} | ||
|
||
public SampleWithIdClass(Long first, Long second) { | ||
this.first = first; | ||
this.second = second; | ||
this.isNew = true; | ||
} | ||
|
||
/** | ||
* @return the first | ||
*/ | ||
public Long getFirst() { | ||
return first; | ||
} | ||
|
||
/** | ||
* @return the second | ||
*/ | ||
public Long getSecond() { | ||
return second; | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see org.springframework.data.domain.Persistable#getId() | ||
*/ | ||
public SampleWithIdClassPK getId() { | ||
return new SampleWithIdClassPK(first, second); | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see org.springframework.data.domain.Persistable#isNew() | ||
*/ | ||
public boolean isNew() { | ||
return this.isNew; | ||
} | ||
|
||
public void setNotNew() { | ||
this.isNew = false; | ||
} | ||
} |
Oops, something went wrong.
3962f1a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am developing a project that uses spring data jpa for persist data. I had faced the problem that CrudRepository class could not be applied for a class that had more than one primary keys, defined using @IdClass. Does the above commit add this fuctionality in spring data jpa? The current release of spring-data- jpa 1.0.3 RELEASE doesn't include the above changes. Do you have any idea in which version this feature will be introduced and when it is estimated this release to become live?
Many thanks!