Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8980383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:04:33+00:00 2026-06-15T20:04:33+00:00

public <S extends T> List<S> save(Iterable<S> entities) { //… } If I use following

  • 0
public <S extends T> List<S> save(Iterable<S> entities) {
        //...
}

If I use following method to override

@Override
public List<MyType> save(Iterable<MyType> structures) {
    List<MyType> result = new ArrayList<>();
    //...
    return result;
}

I get following error:

method does not override or implement a method from a supertype

name clash: save(Iterable<MyType>) in MyTypeRepositoryImpl and <S>save(Iterable<S>) in SimpleJpaRepository have the same erasure, yet neither overrides the other
  where S,T are type-variables:
    S extends T declared in method <S>save(Iterable<S>)
    T extends Object declared in class SimpleJpaRepository

How can I solve this? I don’t need the method to be generic and in fact it should not be. What I mean is that

@Override
public <S extends MyType> List<S> save(Iterable<S> structures) {
    List<S> result = new ArrayList<>();
    //...
    return result;
}

Will not work as the method can create a new Object of MyType which is not “compatible” to List.

How can I make this work?

EDIT:

For clarification. I’m trying to override the different save() methods of Spring data SimpleJpaRepository (which is extented by QuerydslJpaRepository)

Class defintions:

public class MyTypeRepositoryImpl
    extends QueryDslJpaRepository<MyType, Long>
    implements MyTypeRepository

@NoRepositoryBean
public interface MyTypeRepository
    extends JpaRepository<MyType, Long>,
    QueryDslPredicateExecutor<MyType> 

And this (from Spring Data)

public class QueryDslJpaRepository<T, ID extends Serializable> 
extends SimpleJpaRepository<T, ID> 
implements QueryDslPredicateExecutor<T>

EDIT 2:

The method calls save(MyType entity) for each element and that method contains following logic:

  1. entity has a field which is unique
  2. get that fields value and check if entity with that value already exists
  3. if yes, use that entity (call to entityManager.merge) -> does not work returns MyType not S
  4. if no create a new one -> here new object is created. Does not work with generic type

For 4. I can just set id = null and use the passed in object. That does not work for 3.

So I’m very puzzled why this method has this signature. It makes it unusable for me and i don’t get why I would save a subclass of T using Ts DAO. the save methods are the only ones with . All others just use T. I could just cast to S to make it compile but that seems ugly too…as any other type than T would lead to an exception.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T20:04:34+00:00Added an answer on June 15, 2026 at 8:04 pm

    My solution was to not override this at all but to create a service class that does the needed logic and leave repository untouched.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the java code about JPanel : class Battle_field extends JPanel{ public List<Image_Obj>
Say I have this code - public interface ParentInterface1 { public List<? extends ChildInterface1>
public class HttpPostTask extends AsyncTask<Void, Integer, Void> { TextView txtStatus = (TextView)findViewById(R.id.txtStatus); @Override protected
public class SettingsActivity extends SherlockPreferenceActivity implements OnSharedPreferenceChangeListener, OnPreferenceChangeListener { @SuppressWarnings(deprecation) @Override protected void onCreate(Bundle
I have the following model (playframework): @Entity public class Album extends Model{ public Album(){
<?php class ProjectTest extends CDbTestCase { public function testCRUD() { $newProject = new Project;
I have a little problem understanding the Java language public class PhonebookEntryList extends List<PhonebookEntry>
I wrote a template class which extends STL list for some use. I declare
public class tryAnimActivity extends Activity { /** * The thread to process splash screen
public class ExampleActivity extends Activity { public static final int DIALOG_DOWNLOAD_PROGRESS = 0; private

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.