How to display array Range<LocalDate>[] in a JSP page

I can’t see my Range< LocalDate > array in the JSP page. What did I do wrong?
If jsp pages were born to merge html and java, why are scriptlets not recommended? However I found a suggestion where I am advised to use out.print within a scriptlet, but I should instantiate the Parlamentare class, I don’t understand why my for doesn’t work.

parlamentari.jsp

<h2>Lista dei parlamentari:</h2>
<form action="getParlamentari">
 <c:forEach items="${parlamentari}" var="parlamentare">
 

  <tr>
  <td>Periodi delle cariche:</td>
  <c:forEach items="${parlamentare.periodi_cariche}" 
 var="periodo_carica">
   <table>
    <tr>
   <td>Periodo carica:</td> 
   <td><c:out value="${periodo_carica}"/></td>
   </tr>
   </table>
   </c:forEach>
 </tr>
 </table>
</c:forEach>
 </form>

ParlamentareController.java

@Controller
@ComponentScan({"com.giuggiola.controller"})//poi toglilo
public class ParlamentareController //extends 
AbstractController<Parlamentare>
{

@Autowired
 ParlamentareRepository parlamRepo;	

//@RequestMapping("/parlamentari")
@RequestMapping("/")
public ModelAndView home(Parlamentare parlamentare) 
{	
	ModelAndView mv= new ModelAndView();
	Iterable<Parlamentare> parlamentari = parlamRepo.findAll();
	mv.addObject("parlamentari",parlamentari);
	mv.setViewName("parlamentari.jsp");
	return mv;//"home.jsp";
}

Parlamentare.java

@NotFound(action = NotFoundAction.IGNORE)
@OneToMany(mappedBy="parlamentare",  cascade=CascadeType.ALL, 
orphanRemoval=true, targetEntity=Range2.class)
  @Type(type = "list-array")
    @Column(
        name = "periodi_cariche",
        columnDefinition = "daterange[]"
    )
 	private List<Range<LocalDate>> periodi_cariche = new 
ArrayList<Range<LocalDate>>();

Range2.java

@Id
@DateTimeFormat(pattern="dd-MM-yyyy")
private Range<LocalDate> periodo;

As far as I understand the approach taken by the Hibernate Types project, it is not possible to auto-generate the schema when using these types. You will have to maintain the DDL manually somehow. So the definition of periodo is wrong since you are not defining the DDL type through a column definition.

Either way, your question has so many aspects that are irrelevant and confusing. Please focus on what is related to Hibernate. In case of issues with the Hibernate types project, please consult the issue tracker of that project: Issues · vladmihalcea/hibernate-types · GitHub instead, as this forum is for issues with Hibernate.

And what would be the correct DDL type definition? If I may ask? I was told that to map the Range < LocalDate > array, I would have to create a separate sub-table, which frankly I would have avoided because I didn’t need it, in fact I’m having problems defining the primary key, in the java class of range2 c 'is, but in the database I have removed it, maybe that’s the problem?

I don’t know what your model should look like. You will have to figure out yourself what DDL type is right for you, but I guess usually people use tsrange for PostgreSQL. I have no idea how a tsrange could be a meaningful primary key. AFAIU that datatype, the main use case for it is to create exclusion constraints on columns of that type to avoid multiple rows having overlapping date ranges, but that’s different from the primary key.

Maybe try stepping away from your application and tackle the issue from the database side. First, define the DDL and do some sample SQL queries to see if that fits your needs. If you have a table model that works for you, you can try to configure your entities accordingly to produce that schema and be able to work with the data.

1 Like

Ok thanks for the suggestions and your time, I’ll try.