The simplest way

git remote -v

#result something similar to the following
origin  git@github.com:CodepediaOrg/codepediaorg.github.io.git (fetch)
origin  git@github.com:CodepediaOrg/codepediaorg.github.io.git (push)

Tip to get only the remote URL:

git config --get remote.origin.url

#result something similar to the following
git@github.com:CodepediaOrg/codepediaorg.github.io.git

In order to get more details about a particular remote, use the git remote show [remote-name] command

git remote show origin # here "origin" is the remote name

#result something similar to the following
* remote origin
  Fetch URL: git@github.com:CodepediaOrg/codepediaorg.github.io.git
  Push  URL: git@github.com:CodepediaOrg/codepediaorg.github.io.git
  HEAD branch: master
  Remote branches:
    _posts/2016-08-26-migrate-rest-api-from-jboss-eap6-to-eap7 tracked
    add_multiple_authors_functionality                         tracked
    dependabot/npm_and_yarn/bl-1.2.3                           tracked
    dependabot/npm_and_yarn/grunt-1.3.0                        tracked
    dependabot/npm_and_yarn/hosted-git-info-2.8.9              tracked
    dependabot/npm_and_yarn/ini-1.3.7                          tracked
    dependabot/npm_and_yarn/is-svg-4.3.1                       tracked
    dependabot/npm_and_yarn/lodash-4.17.21                     tracked
    dependabot/npm_and_yarn/path-parse-1.0.7                   new (next fetch will store in remotes/origin)
    dependabot/npm_and_yarn/websocket-extensions-0.1.4         tracked
    feature/add-copy-button-for-code-snippets                  tracked
    feature/add-scroll-up-for-posts                            tracked
    feature/mongo-commands-via-collections                     tracked
    gh-pages                                                   tracked
    master                                                     tracked
    post/multiple-authors-jekyll                               tracked
    refs/remotes/origin/dependabot/npm_and_yarn/lodash-4.17.19 stale (use 'git remote prune' to remove)
    run-grunt                                                  tracked
  Local branches configured for 'git pull':
    master    merges with remote master
    run-grunt merges with remote run-grunt
  Local refs configured for 'git push':
    master    pushes to master    (up to date)
    run-grunt pushes to run-grunt (up to date)

Shared with from Codever.land. 👉 Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

Use the find method of the EntityManager, where the primary key is provided as the second parameter:

@Stateless
public class PartnerRepository {

  @Inject private EntityManager em;

  public Optional<Partner> find(String partnerNumber) {
    return Optional.ofNullable(em.find(Partner.class, partnerNumber));
  }
}

The entity looks something like the following, with partnerNumber as primary key:

@Entity
@Access(AccessType.FIELD)
@Table(name = "T_PARTNER")
public class Partner {

  @Id
  @NotNull
  @Column(name = "PARTNER_NUMBER", nullable = false)
  private Integer partnerNumer;

  //other fields ignored for readability
}

Shared with from Codever.land. 👉 Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

The native SQL query we want to map in JPA is similar to the following:

SELECT * FROM PARTNER where PARTNER_NUMBER IN ('id1', 'idn').

With JPA you can use a TypedQuery for example and set the expected list of the IN clause directly as query parameter

@Stateless
public class PartnerDataRepository {

	@Inject private EntityManager em;

	public List<PartnerData> findPartnerDataFromList(
		List<String> partnerNumbers) {
	  TypedQuery<PartnerData> query =
		  em.createNamedQuery(
			  PartnerData.FIND_PARTNER_DATA_IN_LIST, PartnerData.class);
	  query.setParameter(PartnerData.PARTNER_NUMBERS, partnerNumbers);

	  return query.getResultList();
	}
}

In the named query itself you can pass the parameter with : as you would when setting a “normal” parameter:

@Entity
@Access(AccessType.FIELD)
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Table(name = PartnerData.TABLE_NAME)
@NamedQueries({
  @NamedQuery(
      name = PartnerData.FIND_PARTNER_DATA_IN_LIST,
      query = "select m from PartnerData m where partnerNumber in :partnerNumbers")
})
public class PartnerData {
  public static final String TABLE_NAME = "PARTNER";

  public static final String PARTNER_NUMBERS = "partnerNumbers";
  public static final String FIND_PARTNER_DATA_IN_LIST =
      "findPartnerDataWithPartnerNumbers";

  //... rest ignored for brevity
}


Shared with from Codever.land. 👉 Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

The native SQL query we want to map in JPA is similar to the following:

select *
from PARTNER
where EVENT_TIMESTAMP >= timestamp '2021-09-17 10:00:00'
  and EVENT_TIMESTAMP < timestamp '2021-09-17 11:00:00'

where the two timestamps should come as query parameters.

With JPA you can use a TypedQuery for example and set the LocalDateTime values to query parameters via the setParameter method:

@Stateless
public class PartnerDataRepository {

    @Inject private EntityManager em;

    public List<PartnerData> findPartnerDataWithinInterval(
      LocalDateTime fromDatetime, LocalDateTime toDatetime) {
        TypedQuery<PartnerData> query =
            em.createNamedQuery(
                PartnerData.FIND_PARTNER_DATA_IN_TIME_INTERVAL, PartnerData.class);

        query.setParameter(PartnerData.FROM_DATETIME, fromDatetime);
        query.setParameter(PartnerData.TO_DATETIME, toDatetime);

        return query.getResultList();
    }
}

In the named query itself you can directly pass the parameters before : as usual, and the implementation (in my case Hibernate) takes care of the rest :

@Entity
@Access(AccessType.FIELD)
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Table(name = PartnerData.TABLE_NAME)
@NamedQueries({
 @NamedQuery(
      name = PartnerKerndaten.FIND_PARTNER_DATA_IN_TIME_INTERVAL,
      query = "select m from PartnerData m where eventTimestamp >= :fromDatetime and eventTimestamp < :toDatetime")
})
public class PartnerData {
  public static final String TABLE_NAME = "PARTNER";

  public static final String FROM_DATETIME = "fromDatetime";
  public static final String TO_DATETIME = "toDatetime";

  public static final String FIND_PARTNER_DATA_IN_TIME_INTERVAL =
      "findPartnerDataWithinInterval";

  //... rest ignored for brevity
}

Shared with from Codever.land. 👉 Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

Use parse method and apply withNano with value 0 seconds on the result

final var fromDateTime = LocalDateTime.parse("2017-02-26T01:02:03").withNano(0);

Shared with from Codever.land. 👉 Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.