---
# System prepended metadata

title: PSK 1 laboras know-how

---

# PSK 1 laboras know-how

* Jeigu kazkuriuo momentu apps'as nebekraus H2
```
[org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (ServerService Thread Pool -- 26) IJ000604: Throwable while attempting to get a new connection: null: javax.resource.ResourceException: IJ031084: Unable to create connection
```

Pakeiskit DB pavadinima (PlayerDB) config failuose ir prades vel veikt

* Jeigu norit isimest spring-data-jpa, tai isimeskit dependency i pom.xml, tada vietoj Resources.java isimeskit CdiConfig.java
```java
package lt.vu.persistence;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.Dependent;
import javax.enterprise.inject.Produces;
import javax.persistence.*;

@ApplicationScoped
public class CdiConfig {

    @Produces
    @Dependent
    @PersistenceContext
    private EntityManager entityManager;

}

```

(bl man atrodo dar kazka pamirsau)

Tuomet naudot labai paprasta

```java
    @Inject
    private BookRepository bookRepository;
    
    public List<Book> getBooks() {
        bookRepository.findAll();
    }
```

* Jeigu naudojat @ManyToMany (ar kitus relationshipus) ir gaunat LazyLoadingException (berods taip vadinas), tai prirasykit sita
```java
    @ManyToMany(fetch = FetchType.EAGER)
```

* Kaip sugeneruoti MyBatis? Nesu tikras ar visi steps'ai butini (gal isvis tik 5 uzteks)
1. Einat i generatorConfig.xml, sitas linkas turetu buti red:
`"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"`
Paspaudziat alt+enter ir pasirenkat fetch external resource

2. I ta pati generatorConfig.xml prirasot savo tables
```
        <table schema="public" tableName="team">
            <generatedKey column="id" identity="true" sqlStatement="JDBC" />
        </table>
        ...
```

3. I pom.xml prisidedat. Po sito turetu bent jau neraudonuot mybatis-generator-maven-plugin

```
<dependencies>
...
        <dependency>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-core</artifactId>
            <version>1.4.0</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-maven-plugin</artifactId>
            <version>1.4.0</version>
        </dependency>
...
</dependencies>
```

4. Susibuildinkit projekta (tiesiog pasileiskit, arba mvn clean install)

5. Per terminala projekto root folderyje (ten, kur pom.xml) paleiskit `mvn mybatis-generator:generate` Jei gaunat database-related errora, tai bandykit pakeist DB pavadinima. Pries tai, zinoma, parsisiuskit maven.

Btw, nepamirskit virs mapperiu prirasyt `@Mapper` kitaip nesuinjectins + paeditint MyBatisConfig.xml. Jeigu meta errorą kad neranda type'ų, atkreipkit dėmesį į tai ar namespace'ai (ne package'ai, o xml namespace'ai) geri tam MyBaticConfig'e.

